Lines Matching full:ns
44 ns_printf(struct nvmf_namespace *ns, const char *fmt, ...) in ns_printf() argument
53 sbuf_printf(&sb, "%sn%u: ", device_get_nameunit(ns->sc->dev), in ns_printf()
54 ns->id); in ns_printf()
79 struct nvmf_namespace *ns; in nvmf_ns_biodone() local
85 ns = bio->bio_dev->si_drv1; in nvmf_ns_biodone()
91 mtx_lock(&ns->lock); in nvmf_ns_biodone()
92 if (ns->disconnected) { in nvmf_ns_biodone()
93 if (nvmf_fail_disconnect || ns->shutdown) { in nvmf_ns_biodone()
94 mtx_unlock(&ns->lock); in nvmf_ns_biodone()
100 TAILQ_INSERT_TAIL(&ns->pending_bios, bio, in nvmf_ns_biodone()
102 mtx_unlock(&ns->lock); in nvmf_ns_biodone()
105 mtx_unlock(&ns->lock); in nvmf_ns_biodone()
121 if (refcount_release(&ns->active_bios)) in nvmf_ns_biodone()
122 wakeup(ns); in nvmf_ns_biodone()
169 nvmf_ns_submit_bio(struct nvmf_namespace *ns, struct bio *bio) in nvmf_ns_submit_bio() argument
182 lba = bio->bio_offset / ns->lba_size; in nvmf_ns_submit_bio()
183 lba_count = bio->bio_bcount / ns->lba_size; in nvmf_ns_submit_bio()
184 nvme_ns_read_cmd(&cmd, ns->id, lba, lba_count); in nvmf_ns_submit_bio()
187 lba = bio->bio_offset / ns->lba_size; in nvmf_ns_submit_bio()
188 lba_count = bio->bio_bcount / ns->lba_size; in nvmf_ns_submit_bio()
189 nvme_ns_write_cmd(&cmd, ns->id, lba, lba_count); in nvmf_ns_submit_bio()
192 nvme_ns_flush_cmd(&cmd, ns->id); in nvmf_ns_submit_bio()
199 lba = bio->bio_offset / ns->lba_size; in nvmf_ns_submit_bio()
200 lba_count = bio->bio_bcount / ns->lba_size; in nvmf_ns_submit_bio()
205 cmd.nsid = htole32(ns->id); in nvmf_ns_submit_bio()
213 mtx_lock(&ns->lock); in nvmf_ns_submit_bio()
214 if (ns->disconnected) { in nvmf_ns_submit_bio()
215 if (nvmf_fail_disconnect || ns->shutdown) { in nvmf_ns_submit_bio()
218 TAILQ_INSERT_TAIL(&ns->pending_bios, bio, bio_queue); in nvmf_ns_submit_bio()
221 mtx_unlock(&ns->lock); in nvmf_ns_submit_bio()
226 req = nvmf_allocate_request(nvmf_select_io_queue(ns->sc), &cmd, in nvmf_ns_submit_bio()
229 mtx_unlock(&ns->lock); in nvmf_ns_submit_bio()
256 refcount_acquire(&ns->active_bios); in nvmf_ns_submit_bio()
258 mtx_unlock(&ns->lock); in nvmf_ns_submit_bio()
266 struct nvmf_namespace *ns = dev->si_drv1; in nvmf_ns_ioctl() local
273 pt->cmd.nsid = htole32(ns->id); in nvmf_ns_ioctl()
274 return (nvmf_passthrough_cmd(ns->sc, pt, false)); in nvmf_ns_ioctl()
277 strlcpy(gnsid->cdev, device_get_nameunit(ns->sc->dev), in nvmf_ns_ioctl()
279 gnsid->nsid = ns->id; in nvmf_ns_ioctl()
282 *(off_t *)arg = ns->size; in nvmf_ns_ioctl()
285 *(u_int *)arg = ns->lba_size; in nvmf_ns_ioctl()
306 struct nvmf_namespace *ns; in nvmf_ns_strategy() local
309 ns = bio->bio_dev->si_drv1; in nvmf_ns_strategy()
311 error = nvmf_ns_submit_bio(ns, bio); in nvmf_ns_strategy()
335 struct nvmf_namespace *ns; in nvmf_init_ns() local
339 ns = malloc(sizeof(*ns), M_NVMF, M_WAITOK | M_ZERO); in nvmf_init_ns()
340 ns->sc = sc; in nvmf_init_ns()
341 ns->id = id; in nvmf_init_ns()
342 TAILQ_INIT(&ns->pending_bios); in nvmf_init_ns()
343 mtx_init(&ns->lock, "nvmf ns", NULL, MTX_DEF); in nvmf_init_ns()
346 refcount_init(&ns->active_bios, 1); in nvmf_init_ns()
349 ns_printf(ns, "End-to-end data protection not supported\n"); in nvmf_init_ns()
355 ns_printf(ns, "Invalid LBA format index\n"); in nvmf_init_ns()
360 ns_printf(ns, "Namespaces with metadata are not supported\n"); in nvmf_init_ns()
366 ns_printf(ns, "Invalid LBA format index\n"); in nvmf_init_ns()
370 ns->lba_size = 1 << lbads; in nvmf_init_ns()
371 ns->size = data->nsze * ns->lba_size; in nvmf_init_ns()
374 ns->flags |= NVME_NS_DEALLOCATE_SUPPORTED; in nvmf_init_ns()
377 ns->flags |= NVME_NS_FLUSH_SUPPORTED; in nvmf_init_ns()
389 mda.mda_si_drv1 = ns; in nvmf_init_ns()
390 error = make_dev_s(&mda, &ns->cdev, "%sn%u", in nvmf_init_ns()
394 ns->cdev->si_drv2 = make_dev_alias(ns->cdev, "%sns%u", in nvmf_init_ns()
397 ns->cdev->si_flags |= SI_UNMAPPED; in nvmf_init_ns()
399 return (ns); in nvmf_init_ns()
401 mtx_destroy(&ns->lock); in nvmf_init_ns()
402 free(ns, M_NVMF); in nvmf_init_ns()
407 nvmf_disconnect_ns(struct nvmf_namespace *ns) in nvmf_disconnect_ns() argument
409 mtx_lock(&ns->lock); in nvmf_disconnect_ns()
410 ns->disconnected = true; in nvmf_disconnect_ns()
411 mtx_unlock(&ns->lock); in nvmf_disconnect_ns()
415 nvmf_reconnect_ns(struct nvmf_namespace *ns) in nvmf_reconnect_ns() argument
420 mtx_lock(&ns->lock); in nvmf_reconnect_ns()
421 ns->disconnected = false; in nvmf_reconnect_ns()
423 TAILQ_CONCAT(&bios, &ns->pending_bios, bio_queue); in nvmf_reconnect_ns()
424 mtx_unlock(&ns->lock); in nvmf_reconnect_ns()
434 nvmf_shutdown_ns(struct nvmf_namespace *ns) in nvmf_shutdown_ns() argument
439 mtx_lock(&ns->lock); in nvmf_shutdown_ns()
440 ns->shutdown = true; in nvmf_shutdown_ns()
442 TAILQ_CONCAT(&bios, &ns->pending_bios, bio_queue); in nvmf_shutdown_ns()
443 mtx_unlock(&ns->lock); in nvmf_shutdown_ns()
456 nvmf_destroy_ns(struct nvmf_namespace *ns) in nvmf_destroy_ns() argument
461 if (ns->cdev->si_drv2 != NULL) in nvmf_destroy_ns()
462 destroy_dev(ns->cdev->si_drv2); in nvmf_destroy_ns()
463 destroy_dev(ns->cdev); in nvmf_destroy_ns()
470 mtx_lock(&ns->lock); in nvmf_destroy_ns()
471 if (!refcount_release(&ns->active_bios)) { in nvmf_destroy_ns()
472 while (ns->active_bios != 0) in nvmf_destroy_ns()
473 mtx_sleep(ns, &ns->lock, 0, "nvmfrmns", 0); in nvmf_destroy_ns()
478 TAILQ_CONCAT(&bios, &ns->pending_bios, bio_queue); in nvmf_destroy_ns()
479 mtx_unlock(&ns->lock); in nvmf_destroy_ns()
490 mtx_destroy(&ns->lock); in nvmf_destroy_ns()
491 free(ns, M_NVMF); in nvmf_destroy_ns()
495 nvmf_update_ns(struct nvmf_namespace *ns, in nvmf_update_ns() argument
501 ns_printf(ns, "End-to-end data protection not supported\n"); in nvmf_update_ns()
507 ns_printf(ns, "Invalid LBA format index\n"); in nvmf_update_ns()
512 ns_printf(ns, "Namespaces with metadata are not supported\n"); in nvmf_update_ns()
518 ns_printf(ns, "Invalid LBA format index\n"); in nvmf_update_ns()
522 ns->lba_size = 1 << lbads; in nvmf_update_ns()
523 ns->size = data->nsze * ns->lba_size; in nvmf_update_ns()