Lines Matching +full:fiq +full:- +full:index
1 // SPDX-License-Identifier: GPL-2.0
3 * virtio-fs: Virtio Filesystem
31 /* List of virtio-fs device instances and a lock for the list. Also provides
47 /* Per-virtqueue state */
50 struct virtqueue *vq; /* protected by ->lock */
63 /* A virtio-fs device instance */
74 unsigned int *mq_map; /* index = cpu id, value = request vq id */
124 struct fuse_fs_context *ctx = fsc->fs_private; in virtio_fs_parse_param()
133 ctx->dax_mode = FUSE_DAX_ALWAYS; in virtio_fs_parse_param()
136 ctx->dax_mode = result.uint_32; in virtio_fs_parse_param()
139 return -EINVAL; in virtio_fs_parse_param()
147 struct fuse_fs_context *ctx = fsc->fs_private; in virtio_fs_free_fsc()
154 struct virtio_fs *fs = vq->vdev->priv; in vq_to_fsvq()
156 return &fs->vqs[vq->index]; in vq_to_fsvq()
159 /* Should be called with fsvq->lock held. */
162 fsvq->in_flight++; in inc_in_flight_req()
165 /* Should be called with fsvq->lock held. */
168 WARN_ON(fsvq->in_flight <= 0); in dec_in_flight_req()
169 fsvq->in_flight--; in dec_in_flight_req()
170 if (!fsvq->in_flight) in dec_in_flight_req()
171 complete(&fsvq->in_flight_zero); in dec_in_flight_req()
179 return sysfs_emit(buf, "%s\n", fs->tag); in tag_show()
194 kfree(vfs->mq_map); in virtio_fs_ktype_release()
195 kfree(vfs->vqs); in virtio_fs_ktype_release()
210 for (i = 0; i < fs->nvqs; i++) { in virtio_fs_kobj_to_vq()
211 if (kobj == fs->vqs[i].kobj) in virtio_fs_kobj_to_vq()
212 return &fs->vqs[i]; in virtio_fs_kobj_to_vq()
220 struct virtio_fs *fs = container_of(kobj->parent->parent, struct virtio_fs, kobj); in name_show()
224 return -EINVAL; in name_show()
225 return sysfs_emit(buf, "%s\n", fsvq->name); in name_show()
233 struct virtio_fs *fs = container_of(kobj->parent->parent, struct virtio_fs, kobj); in cpu_list_show()
236 const size_t size = PAGE_SIZE - 1; in cpu_list_show()
241 return -EINVAL; in cpu_list_show()
243 qid = fsvq->vq->index; in cpu_list_show()
245 if (qid < VQ_REQUEST || (fs->mq_map[cpu] == qid - VQ_REQUEST)) { in cpu_list_show()
247 ret = snprintf(buf + pos, size - pos, "%u", cpu); in cpu_list_show()
249 ret = snprintf(buf + pos, size - pos, ", %u", cpu); in cpu_list_show()
251 if (ret >= size - pos) in cpu_list_show()
257 ret = snprintf(buf + pos, size + 1 - pos, "\n"); in cpu_list_show()
278 kobject_put(&fs->kobj); in virtio_fs_put_locked()
288 static void virtio_fs_fiq_release(struct fuse_iqueue *fiq) in virtio_fs_fiq_release() argument
290 struct virtio_fs *vfs = fiq->priv; in virtio_fs_fiq_release()
297 WARN_ON(fsvq->in_flight < 0); in virtio_fs_drain_queue()
300 spin_lock(&fsvq->lock); in virtio_fs_drain_queue()
301 if (fsvq->in_flight) { in virtio_fs_drain_queue()
305 reinit_completion(&fsvq->in_flight_zero); in virtio_fs_drain_queue()
306 spin_unlock(&fsvq->lock); in virtio_fs_drain_queue()
307 wait_for_completion(&fsvq->in_flight_zero); in virtio_fs_drain_queue()
309 spin_unlock(&fsvq->lock); in virtio_fs_drain_queue()
312 flush_work(&fsvq->done_work); in virtio_fs_drain_queue()
313 flush_work(&fsvq->dispatch_work); in virtio_fs_drain_queue()
321 for (i = 0; i < fs->nvqs; i++) { in virtio_fs_drain_all_queues_locked()
322 fsvq = &fs->vqs[i]; in virtio_fs_drain_all_queues_locked()
329 /* Provides mutual exclusion between ->remove and ->kill_sb in virtio_fs_drain_all_queues()
345 for (i = 0; i < fs->nvqs; i++) { in virtio_fs_start_all_queues()
346 fsvq = &fs->vqs[i]; in virtio_fs_start_all_queues()
347 spin_lock(&fsvq->lock); in virtio_fs_start_all_queues()
348 fsvq->connected = true; in virtio_fs_start_all_queues()
349 spin_unlock(&fsvq->lock); in virtio_fs_start_all_queues()
358 for (i = 0; i < fs->nvqs; i++) { in virtio_fs_delete_queues_sysfs()
359 fsvq = &fs->vqs[i]; in virtio_fs_delete_queues_sysfs()
360 kobject_put(fsvq->kobj); in virtio_fs_delete_queues_sysfs()
370 for (i = 0; i < fs->nvqs; i++) { in virtio_fs_add_queues_sysfs()
371 fsvq = &fs->vqs[i]; in virtio_fs_add_queues_sysfs()
374 fsvq->kobj = kobject_create_and_add(buff, fs->mqs_kobj); in virtio_fs_add_queues_sysfs()
375 if (!fs->mqs_kobj) { in virtio_fs_add_queues_sysfs()
376 ret = -ENOMEM; in virtio_fs_add_queues_sysfs()
380 ret = sysfs_create_group(fsvq->kobj, &virtio_fs_vq_attr_group); in virtio_fs_add_queues_sysfs()
382 kobject_put(fsvq->kobj); in virtio_fs_add_queues_sysfs()
391 fsvq = &fs->vqs[j]; in virtio_fs_add_queues_sysfs()
392 kobject_put(fsvq->kobj); in virtio_fs_add_queues_sysfs()
397 /* Add a new instance to the list or return -EEXIST if tag name exists*/
407 if (strcmp(fs->tag, fs2->tag) == 0) { in virtio_fs_add_instance()
409 return -EEXIST; in virtio_fs_add_instance()
413 /* Use the virtio_device's index as a unique identifier, there is no in virtio_fs_add_instance()
418 fs->kobj.kset = virtio_fs_kset; in virtio_fs_add_instance()
419 ret = kobject_add(&fs->kobj, NULL, "%d", vdev->index); in virtio_fs_add_instance()
423 fs->mqs_kobj = kobject_create_and_add("mqs", &fs->kobj); in virtio_fs_add_instance()
424 if (!fs->mqs_kobj) { in virtio_fs_add_instance()
425 ret = -ENOMEM; in virtio_fs_add_instance()
429 ret = sysfs_create_link(&fs->kobj, &vdev->dev.kobj, "device"); in virtio_fs_add_instance()
437 list_add_tail(&fs->list, &virtio_fs_instances); in virtio_fs_add_instance()
441 kobject_uevent(&fs->kobj, KOBJ_ADD); in virtio_fs_add_instance()
446 sysfs_remove_link(&fs->kobj, "device"); in virtio_fs_add_instance()
448 kobject_put(fs->mqs_kobj); in virtio_fs_add_instance()
450 kobject_del(&fs->kobj); in virtio_fs_add_instance()
464 if (strcmp(fs->tag, tag) == 0) { in virtio_fs_find_instance()
465 kobject_get(&fs->kobj); in virtio_fs_find_instance()
482 for (i = 0; i < fs->nvqs; i++) { in virtio_fs_free_devs()
483 struct virtio_fs_vq *fsvq = &fs->vqs[i]; in virtio_fs_free_devs()
485 if (!fsvq->fud) in virtio_fs_free_devs()
488 fuse_dev_free(fsvq->fud); in virtio_fs_free_devs()
489 fsvq->fud = NULL; in virtio_fs_free_devs()
493 /* Read filesystem name from virtio config into fs->tag (must kfree()). */
504 return -EINVAL; /* empty tag */ in virtio_fs_read_tag()
508 len = end - tag_buf; in virtio_fs_read_tag()
509 fs->tag = devm_kmalloc(&vdev->dev, len + 1, GFP_KERNEL); in virtio_fs_read_tag()
510 if (!fs->tag) in virtio_fs_read_tag()
511 return -ENOMEM; in virtio_fs_read_tag()
512 memcpy(fs->tag, tag_buf, len); in virtio_fs_read_tag()
513 fs->tag[len] = '\0'; in virtio_fs_read_tag()
516 * awkward on mount(8) command-lines and cause problems in the sysfs in virtio_fs_read_tag()
519 if (strchr(fs->tag, '\n')) { in virtio_fs_read_tag()
520 dev_dbg(&vdev->dev, "refusing virtiofs tag with newline character\n"); in virtio_fs_read_tag()
521 return -EINVAL; in virtio_fs_read_tag()
532 struct virtqueue *vq = fsvq->vq; in virtio_fs_hiprio_done_work()
535 spin_lock(&fsvq->lock); in virtio_fs_hiprio_done_work()
548 if (!list_empty(&fsvq->queued_reqs)) in virtio_fs_hiprio_done_work()
549 schedule_work(&fsvq->dispatch_work); in virtio_fs_hiprio_done_work()
551 spin_unlock(&fsvq->lock); in virtio_fs_hiprio_done_work()
561 pr_debug("virtio-fs: worker %s called.\n", __func__); in virtio_fs_request_dispatch_work()
563 spin_lock(&fsvq->lock); in virtio_fs_request_dispatch_work()
564 req = list_first_entry_or_null(&fsvq->end_reqs, struct fuse_req, in virtio_fs_request_dispatch_work()
567 spin_unlock(&fsvq->lock); in virtio_fs_request_dispatch_work()
571 list_del_init(&req->list); in virtio_fs_request_dispatch_work()
572 spin_unlock(&fsvq->lock); in virtio_fs_request_dispatch_work()
578 spin_lock(&fsvq->lock); in virtio_fs_request_dispatch_work()
579 req = list_first_entry_or_null(&fsvq->queued_reqs, in virtio_fs_request_dispatch_work()
582 spin_unlock(&fsvq->lock); in virtio_fs_request_dispatch_work()
585 list_del_init(&req->list); in virtio_fs_request_dispatch_work()
586 spin_unlock(&fsvq->lock); in virtio_fs_request_dispatch_work()
590 if (ret == -ENOSPC) { in virtio_fs_request_dispatch_work()
591 spin_lock(&fsvq->lock); in virtio_fs_request_dispatch_work()
592 list_add_tail(&req->list, &fsvq->queued_reqs); in virtio_fs_request_dispatch_work()
593 spin_unlock(&fsvq->lock); in virtio_fs_request_dispatch_work()
596 req->out.h.error = ret; in virtio_fs_request_dispatch_work()
597 spin_lock(&fsvq->lock); in virtio_fs_request_dispatch_work()
599 spin_unlock(&fsvq->lock); in virtio_fs_request_dispatch_work()
600 pr_err("virtio-fs: virtio_fs_enqueue_req() failed %d\n", in virtio_fs_request_dispatch_work()
619 struct virtio_fs_forget_req *req = &forget->req; in send_forget_request()
621 spin_lock(&fsvq->lock); in send_forget_request()
622 if (!fsvq->connected) { in send_forget_request()
630 vq = fsvq->vq; in send_forget_request()
631 dev_dbg(&vq->vdev->dev, "%s\n", __func__); in send_forget_request()
635 if (ret == -ENOSPC) { in send_forget_request()
636 pr_debug("virtio-fs: Could not queue FORGET: err=%d. Will try later\n", in send_forget_request()
638 list_add_tail(&forget->list, &fsvq->queued_reqs); in send_forget_request()
644 pr_debug("virtio-fs: Could not queue FORGET: err=%d. Dropping it.\n", in send_forget_request()
656 spin_unlock(&fsvq->lock); in send_forget_request()
662 spin_unlock(&fsvq->lock); in send_forget_request()
671 pr_debug("virtio-fs: worker %s called.\n", __func__); in virtio_fs_hiprio_dispatch_work()
673 spin_lock(&fsvq->lock); in virtio_fs_hiprio_dispatch_work()
674 forget = list_first_entry_or_null(&fsvq->queued_reqs, in virtio_fs_hiprio_dispatch_work()
677 spin_unlock(&fsvq->lock); in virtio_fs_hiprio_dispatch_work()
681 list_del(&forget->list); in virtio_fs_hiprio_dispatch_work()
682 spin_unlock(&fsvq->lock); in virtio_fs_hiprio_dispatch_work()
688 /* Allocate and copy args into req->argbuf */
691 struct fuse_args *args = req->args; in copy_args_to_argbuf()
698 num_in = args->in_numargs - args->in_pages; in copy_args_to_argbuf()
699 num_out = args->out_numargs - args->out_pages; in copy_args_to_argbuf()
700 len = fuse_len_args(num_in, (struct fuse_arg *) args->in_args) + in copy_args_to_argbuf()
701 fuse_len_args(num_out, args->out_args); in copy_args_to_argbuf()
703 req->argbuf = kmalloc(len, GFP_ATOMIC); in copy_args_to_argbuf()
704 if (!req->argbuf) in copy_args_to_argbuf()
705 return -ENOMEM; in copy_args_to_argbuf()
708 memcpy(req->argbuf + offset, in copy_args_to_argbuf()
709 args->in_args[i].value, in copy_args_to_argbuf()
710 args->in_args[i].size); in copy_args_to_argbuf()
711 offset += args->in_args[i].size; in copy_args_to_argbuf()
717 /* Copy args out of and free req->argbuf */
726 remaining = req->out.h.len - sizeof(req->out.h); in copy_args_from_argbuf()
727 num_in = args->in_numargs - args->in_pages; in copy_args_from_argbuf()
728 num_out = args->out_numargs - args->out_pages; in copy_args_from_argbuf()
729 offset = fuse_len_args(num_in, (struct fuse_arg *)args->in_args); in copy_args_from_argbuf()
732 unsigned int argsize = args->out_args[i].size; in copy_args_from_argbuf()
734 if (args->out_argvar && in copy_args_from_argbuf()
735 i == args->out_numargs - 1 && in copy_args_from_argbuf()
740 memcpy(args->out_args[i].value, req->argbuf + offset, argsize); in copy_args_from_argbuf()
743 if (i != args->out_numargs - 1) in copy_args_from_argbuf()
744 remaining -= argsize; in copy_args_from_argbuf()
747 /* Store the actual size of the variable-length arg */ in copy_args_from_argbuf()
748 if (args->out_argvar) in copy_args_from_argbuf()
749 args->out_args[args->out_numargs - 1].size = remaining; in copy_args_from_argbuf()
751 kfree(req->argbuf); in copy_args_from_argbuf()
752 req->argbuf = NULL; in copy_args_from_argbuf()
759 struct fuse_pqueue *fpq = &fsvq->fud->pq; in virtio_fs_request_complete()
769 args = req->args; in virtio_fs_request_complete()
772 if (args->out_pages && args->page_zeroing) { in virtio_fs_request_complete()
773 len = args->out_args[args->out_numargs - 1].size; in virtio_fs_request_complete()
775 for (i = 0; i < ap->num_pages; i++) { in virtio_fs_request_complete()
776 thislen = ap->descs[i].length; in virtio_fs_request_complete()
778 WARN_ON(ap->descs[i].offset); in virtio_fs_request_complete()
779 page = ap->pages[i]; in virtio_fs_request_complete()
783 len -= thislen; in virtio_fs_request_complete()
788 spin_lock(&fpq->lock); in virtio_fs_request_complete()
789 clear_bit(FR_SENT, &req->flags); in virtio_fs_request_complete()
790 spin_unlock(&fpq->lock); in virtio_fs_request_complete()
793 spin_lock(&fsvq->lock); in virtio_fs_request_complete()
795 spin_unlock(&fsvq->lock); in virtio_fs_request_complete()
803 virtio_fs_request_complete(w->req, w->fsvq); in virtio_fs_complete_req_work()
811 struct fuse_pqueue *fpq = &fsvq->fud->pq; in virtio_fs_requests_done_work()
812 struct virtqueue *vq = fsvq->vq; in virtio_fs_requests_done_work()
819 spin_lock(&fsvq->lock); in virtio_fs_requests_done_work()
824 spin_lock(&fpq->lock); in virtio_fs_requests_done_work()
825 list_move_tail(&req->list, &reqs); in virtio_fs_requests_done_work()
826 spin_unlock(&fpq->lock); in virtio_fs_requests_done_work()
829 spin_unlock(&fsvq->lock); in virtio_fs_requests_done_work()
833 list_del_init(&req->list); in virtio_fs_requests_done_work()
836 if (req->args->may_block) { in virtio_fs_requests_done_work()
840 INIT_WORK(&w->done_work, virtio_fs_complete_req_work); in virtio_fs_requests_done_work()
841 w->fsvq = fsvq; in virtio_fs_requests_done_work()
842 w->req = req; in virtio_fs_requests_done_work()
843 schedule_work(&w->done_work); in virtio_fs_requests_done_work()
850 spin_lock(&fsvq->lock); in virtio_fs_requests_done_work()
851 if (!list_empty(&fsvq->queued_reqs)) in virtio_fs_requests_done_work()
852 schedule_work(&fsvq->dispatch_work); in virtio_fs_requests_done_work()
853 spin_unlock(&fsvq->lock); in virtio_fs_requests_done_work()
862 * e.g. PCIe MSI-X in virtio_fs_map_queues()
864 if (!vdev->config->get_vq_affinity) in virtio_fs_map_queues()
867 for (q = 0; q < fs->num_request_queues; q++) { in virtio_fs_map_queues()
868 mask = vdev->config->get_vq_affinity(vdev, VQ_REQUEST + q); in virtio_fs_map_queues()
873 fs->mq_map[cpu] = q; in virtio_fs_map_queues()
879 masks = group_cpus_evenly(fs->num_request_queues); in virtio_fs_map_queues()
883 fs->mq_map[cpu] = 0; in virtio_fs_map_queues()
887 for (q = 0; q < fs->num_request_queues; q++) { in virtio_fs_map_queues()
889 fs->mq_map[cpu] = q; in virtio_fs_map_queues()
899 dev_dbg(&vq->vdev->dev, "%s %s\n", __func__, fsvq->name); in virtio_fs_vq_done()
901 schedule_work(&fsvq->done_work); in virtio_fs_vq_done()
907 strscpy(fsvq->name, name, VQ_NAME_LEN); in virtio_fs_init_vq()
908 spin_lock_init(&fsvq->lock); in virtio_fs_init_vq()
909 INIT_LIST_HEAD(&fsvq->queued_reqs); in virtio_fs_init_vq()
910 INIT_LIST_HEAD(&fsvq->end_reqs); in virtio_fs_init_vq()
911 init_completion(&fsvq->in_flight_zero); in virtio_fs_init_vq()
914 INIT_WORK(&fsvq->done_work, virtio_fs_requests_done_work); in virtio_fs_init_vq()
915 INIT_WORK(&fsvq->dispatch_work, in virtio_fs_init_vq()
918 INIT_WORK(&fsvq->done_work, virtio_fs_hiprio_done_work); in virtio_fs_init_vq()
919 INIT_WORK(&fsvq->dispatch_work, in virtio_fs_init_vq()
932 * the multi-queue mapping and interrupt affinities in virtio_fs_setup_vqs()
939 &fs->num_request_queues); in virtio_fs_setup_vqs()
940 if (fs->num_request_queues == 0) in virtio_fs_setup_vqs()
941 return -EINVAL; in virtio_fs_setup_vqs()
944 fs->num_request_queues = min_t(unsigned int, fs->num_request_queues, in virtio_fs_setup_vqs()
946 fs->nvqs = VQ_REQUEST + fs->num_request_queues; in virtio_fs_setup_vqs()
947 fs->vqs = kcalloc(fs->nvqs, sizeof(fs->vqs[VQ_HIPRIO]), GFP_KERNEL); in virtio_fs_setup_vqs()
948 if (!fs->vqs) in virtio_fs_setup_vqs()
949 return -ENOMEM; in virtio_fs_setup_vqs()
951 vqs = kmalloc_array(fs->nvqs, sizeof(vqs[VQ_HIPRIO]), GFP_KERNEL); in virtio_fs_setup_vqs()
952 fs->mq_map = kcalloc_node(nr_cpu_ids, sizeof(*fs->mq_map), GFP_KERNEL, in virtio_fs_setup_vqs()
953 dev_to_node(&vdev->dev)); in virtio_fs_setup_vqs()
954 vqs_info = kcalloc(fs->nvqs, sizeof(*vqs_info), GFP_KERNEL); in virtio_fs_setup_vqs()
955 if (!vqs || !vqs_info || !fs->mq_map) { in virtio_fs_setup_vqs()
956 ret = -ENOMEM; in virtio_fs_setup_vqs()
962 virtio_fs_init_vq(&fs->vqs[VQ_HIPRIO], "hiprio", VQ_HIPRIO); in virtio_fs_setup_vqs()
963 vqs_info[VQ_HIPRIO].name = fs->vqs[VQ_HIPRIO].name; in virtio_fs_setup_vqs()
966 for (i = VQ_REQUEST; i < fs->nvqs; i++) { in virtio_fs_setup_vqs()
969 snprintf(vq_name, VQ_NAME_LEN, "requests.%u", i - VQ_REQUEST); in virtio_fs_setup_vqs()
970 virtio_fs_init_vq(&fs->vqs[i], vq_name, VQ_REQUEST); in virtio_fs_setup_vqs()
972 vqs_info[i].name = fs->vqs[i].name; in virtio_fs_setup_vqs()
975 ret = virtio_find_vqs(vdev, fs->nvqs, vqs, vqs_info, &desc); in virtio_fs_setup_vqs()
979 for (i = 0; i < fs->nvqs; i++) in virtio_fs_setup_vqs()
980 fs->vqs[i].vq = vqs[i]; in virtio_fs_setup_vqs()
987 kfree(fs->vqs); in virtio_fs_setup_vqs()
988 kfree(fs->mq_map); in virtio_fs_setup_vqs()
996 vdev->config->del_vqs(vdev); in virtio_fs_cleanup_vqs()
1009 size_t max_nr_pages = fs->window_len / PAGE_SIZE - pgoff; in virtio_fs_direct_access()
1012 *kaddr = fs->window_kaddr + offset; in virtio_fs_direct_access()
1014 *pfn = phys_to_pfn_t(fs->window_phys_addr + offset, in virtio_fs_direct_access()
1063 return rc == -EOPNOTSUPP ? 0 : rc; in virtio_fs_setup_dax()
1070 dev_notice(&vdev->dev, "%s: No cache capability\n", __func__); in virtio_fs_setup_dax()
1074 if (!devm_request_mem_region(&vdev->dev, cache_reg.addr, cache_reg.len, in virtio_fs_setup_dax()
1075 dev_name(&vdev->dev))) { in virtio_fs_setup_dax()
1076 dev_warn(&vdev->dev, "could not reserve region addr=0x%llx len=0x%llx\n", in virtio_fs_setup_dax()
1078 return -EBUSY; in virtio_fs_setup_dax()
1081 dev_notice(&vdev->dev, "Cache len: 0x%llx @ 0x%llx\n", cache_reg.len, in virtio_fs_setup_dax()
1084 pgmap = devm_kzalloc(&vdev->dev, sizeof(*pgmap), GFP_KERNEL); in virtio_fs_setup_dax()
1086 return -ENOMEM; in virtio_fs_setup_dax()
1088 pgmap->type = MEMORY_DEVICE_FS_DAX; in virtio_fs_setup_dax()
1095 pgmap->range = (struct range) { in virtio_fs_setup_dax()
1097 .end = (phys_addr_t) cache_reg.addr + cache_reg.len - 1, in virtio_fs_setup_dax()
1099 pgmap->nr_range = 1; in virtio_fs_setup_dax()
1101 fs->window_kaddr = devm_memremap_pages(&vdev->dev, pgmap); in virtio_fs_setup_dax()
1102 if (IS_ERR(fs->window_kaddr)) in virtio_fs_setup_dax()
1103 return PTR_ERR(fs->window_kaddr); in virtio_fs_setup_dax()
1105 fs->window_phys_addr = (phys_addr_t) cache_reg.addr; in virtio_fs_setup_dax()
1106 fs->window_len = (phys_addr_t) cache_reg.len; in virtio_fs_setup_dax()
1108 dev_dbg(&vdev->dev, "%s: window kaddr 0x%px phys_addr 0x%llx len 0x%llx\n", in virtio_fs_setup_dax()
1109 __func__, fs->window_kaddr, cache_reg.addr, cache_reg.len); in virtio_fs_setup_dax()
1111 fs->dax_dev = no_free_ptr(dax_dev); in virtio_fs_setup_dax()
1112 return devm_add_action_or_reset(&vdev->dev, virtio_fs_cleanup_dax, in virtio_fs_setup_dax()
1113 fs->dax_dev); in virtio_fs_setup_dax()
1123 return -ENOMEM; in virtio_fs_probe()
1124 kobject_init(&fs->kobj, &virtio_fs_ktype); in virtio_fs_probe()
1125 vdev->priv = fs; in virtio_fs_probe()
1157 vdev->priv = NULL; in virtio_fs_probe()
1158 kobject_put(&fs->kobj); in virtio_fs_probe()
1167 for (i = 0; i < fs->nvqs; i++) { in virtio_fs_stop_all_queues()
1168 fsvq = &fs->vqs[i]; in virtio_fs_stop_all_queues()
1169 spin_lock(&fsvq->lock); in virtio_fs_stop_all_queues()
1170 fsvq->connected = false; in virtio_fs_stop_all_queues()
1171 spin_unlock(&fsvq->lock); in virtio_fs_stop_all_queues()
1177 struct virtio_fs *fs = vdev->priv; in virtio_fs_remove()
1181 list_del_init(&fs->list); in virtio_fs_remove()
1183 sysfs_remove_link(&fs->kobj, "device"); in virtio_fs_remove()
1184 kobject_put(fs->mqs_kobj); in virtio_fs_remove()
1185 kobject_del(&fs->kobj); in virtio_fs_remove()
1191 vdev->priv = NULL; in virtio_fs_remove()
1201 pr_warn("virtio-fs: suspend/resume not yet supported\n"); in virtio_fs_freeze()
1202 return -EOPNOTSUPP; in virtio_fs_freeze()
1232 static void virtio_fs_send_forget(struct fuse_iqueue *fiq, struct fuse_forget_link *link) in virtio_fs_send_forget() argument
1236 struct virtio_fs *fs = fiq->priv; in virtio_fs_send_forget()
1237 struct virtio_fs_vq *fsvq = &fs->vqs[VQ_HIPRIO]; in virtio_fs_send_forget()
1238 u64 unique = fuse_get_unique(fiq); in virtio_fs_send_forget()
1242 req = &forget->req; in virtio_fs_send_forget()
1244 req->ih = (struct fuse_in_header){ in virtio_fs_send_forget()
1246 .nodeid = link->forget_one.nodeid, in virtio_fs_send_forget()
1250 req->arg = (struct fuse_forget_in){ in virtio_fs_send_forget()
1251 .nlookup = link->forget_one.nlookup, in virtio_fs_send_forget()
1258 static void virtio_fs_send_interrupt(struct fuse_iqueue *fiq, struct fuse_req *req) in virtio_fs_send_interrupt() argument
1269 /* Count number of scatter-gather elements required */
1279 total_len -= this_len; in sg_count_fuse_pages()
1285 /* Return the number of scatter-gather list elements required */
1288 struct fuse_args *args = req->args; in sg_count_fuse_req()
1292 if (args->in_numargs - args->in_pages) in sg_count_fuse_req()
1295 if (args->in_pages) { in sg_count_fuse_req()
1296 size = args->in_args[args->in_numargs - 1].size; in sg_count_fuse_req()
1297 total_sgs += sg_count_fuse_pages(ap->descs, ap->num_pages, in sg_count_fuse_req()
1301 if (!test_bit(FR_ISREPLY, &req->flags)) in sg_count_fuse_req()
1306 if (args->out_numargs - args->out_pages) in sg_count_fuse_req()
1309 if (args->out_pages) { in sg_count_fuse_req()
1310 size = args->out_args[args->out_numargs - 1].size; in sg_count_fuse_req()
1311 total_sgs += sg_count_fuse_pages(ap->descs, ap->num_pages, in sg_count_fuse_req()
1318 /* Add pages to scatter-gather list and return number of elements used */
1332 total_len -= this_len; in sg_init_fuse_pages()
1338 /* Add args to scatter-gather list and return number of elements used */
1347 struct fuse_args_pages *ap = container_of(req->args, typeof(*ap), args); in sg_init_fuse_args()
1351 len = fuse_len_args(numargs - argpages, args); in sg_init_fuse_args()
1357 ap->pages, ap->descs, in sg_init_fuse_args()
1358 ap->num_pages, in sg_init_fuse_args()
1359 args[numargs - 1].size); in sg_init_fuse_args()
1377 struct fuse_args *args = req->args; in virtio_fs_enqueue_req()
1393 ret = -ENOMEM; in virtio_fs_enqueue_req()
1404 sg_init_one(&sg[out_sgs++], &req->in.h, sizeof(req->in.h)); in virtio_fs_enqueue_req()
1406 (struct fuse_arg *)args->in_args, in virtio_fs_enqueue_req()
1407 args->in_numargs, args->in_pages, in virtio_fs_enqueue_req()
1408 req->argbuf, &argbuf_used); in virtio_fs_enqueue_req()
1411 if (test_bit(FR_ISREPLY, &req->flags)) { in virtio_fs_enqueue_req()
1413 &req->out.h, sizeof(req->out.h)); in virtio_fs_enqueue_req()
1415 args->out_args, args->out_numargs, in virtio_fs_enqueue_req()
1416 args->out_pages, in virtio_fs_enqueue_req()
1417 req->argbuf + argbuf_used, NULL); in virtio_fs_enqueue_req()
1425 spin_lock(&fsvq->lock); in virtio_fs_enqueue_req()
1427 if (!fsvq->connected) { in virtio_fs_enqueue_req()
1428 spin_unlock(&fsvq->lock); in virtio_fs_enqueue_req()
1429 ret = -ENOTCONN; in virtio_fs_enqueue_req()
1433 vq = fsvq->vq; in virtio_fs_enqueue_req()
1436 spin_unlock(&fsvq->lock); in virtio_fs_enqueue_req()
1441 fpq = &fsvq->fud->pq; in virtio_fs_enqueue_req()
1442 spin_lock(&fpq->lock); in virtio_fs_enqueue_req()
1443 list_add_tail(&req->list, fpq->processing); in virtio_fs_enqueue_req()
1444 spin_unlock(&fpq->lock); in virtio_fs_enqueue_req()
1445 set_bit(FR_SENT, &req->flags); in virtio_fs_enqueue_req()
1453 spin_unlock(&fsvq->lock); in virtio_fs_enqueue_req()
1459 if (ret < 0 && req->argbuf) { in virtio_fs_enqueue_req()
1460 kfree(req->argbuf); in virtio_fs_enqueue_req()
1461 req->argbuf = NULL; in virtio_fs_enqueue_req()
1471 static void virtio_fs_send_req(struct fuse_iqueue *fiq, struct fuse_req *req) in virtio_fs_send_req() argument
1478 if (req->in.h.opcode != FUSE_NOTIFY_REPLY) in virtio_fs_send_req()
1479 req->in.h.unique = fuse_get_unique(fiq); in virtio_fs_send_req()
1481 clear_bit(FR_PENDING, &req->flags); in virtio_fs_send_req()
1483 fs = fiq->priv; in virtio_fs_send_req()
1484 queue_id = VQ_REQUEST + fs->mq_map[raw_smp_processor_id()]; in virtio_fs_send_req()
1487 __func__, req->in.h.opcode, req->in.h.unique, in virtio_fs_send_req()
1488 req->in.h.nodeid, req->in.h.len, in virtio_fs_send_req()
1489 fuse_len_args(req->args->out_numargs, req->args->out_args), in virtio_fs_send_req()
1492 fsvq = &fs->vqs[queue_id]; in virtio_fs_send_req()
1495 if (ret == -ENOSPC) { in virtio_fs_send_req()
1498 * context as we might be holding fc->bg_lock. in virtio_fs_send_req()
1500 spin_lock(&fsvq->lock); in virtio_fs_send_req()
1501 list_add_tail(&req->list, &fsvq->queued_reqs); in virtio_fs_send_req()
1503 spin_unlock(&fsvq->lock); in virtio_fs_send_req()
1506 req->out.h.error = ret; in virtio_fs_send_req()
1507 pr_err("virtio-fs: virtio_fs_enqueue_req() failed %d\n", ret); in virtio_fs_send_req()
1510 spin_lock(&fsvq->lock); in virtio_fs_send_req()
1511 list_add_tail(&req->list, &fsvq->end_reqs); in virtio_fs_send_req()
1512 schedule_work(&fsvq->dispatch_work); in virtio_fs_send_req()
1513 spin_unlock(&fsvq->lock); in virtio_fs_send_req()
1527 ctx->rootmode = S_IFDIR; in virtio_fs_ctx_set_defaults()
1528 ctx->default_permissions = 1; in virtio_fs_ctx_set_defaults()
1529 ctx->allow_other = 1; in virtio_fs_ctx_set_defaults()
1530 ctx->max_read = UINT_MAX; in virtio_fs_ctx_set_defaults()
1531 ctx->blksize = 512; in virtio_fs_ctx_set_defaults()
1532 ctx->destroy = true; in virtio_fs_ctx_set_defaults()
1533 ctx->no_control = true; in virtio_fs_ctx_set_defaults()
1534 ctx->no_force_umount = true; in virtio_fs_ctx_set_defaults()
1540 struct fuse_conn *fc = fm->fc; in virtio_fs_fill_super()
1541 struct virtio_fs *fs = fc->iq.priv; in virtio_fs_fill_super()
1542 struct fuse_fs_context *ctx = fsc->fs_private; in virtio_fs_fill_super()
1550 * Though we are holding a reference to it, drive ->remove might in virtio_fs_fill_super()
1553 err = -EINVAL; in virtio_fs_fill_super()
1554 if (list_empty(&fs->list)) { in virtio_fs_fill_super()
1555 pr_info("virtio-fs: tag <%s> not found\n", fs->tag); in virtio_fs_fill_super()
1559 err = -ENOMEM; in virtio_fs_fill_super()
1561 for (i = 0; i < fs->nvqs; i++) { in virtio_fs_fill_super()
1562 struct virtio_fs_vq *fsvq = &fs->vqs[i]; in virtio_fs_fill_super()
1564 fsvq->fud = fuse_dev_alloc(); in virtio_fs_fill_super()
1565 if (!fsvq->fud) in virtio_fs_fill_super()
1570 ctx->fudptr = NULL; in virtio_fs_fill_super()
1571 if (ctx->dax_mode != FUSE_DAX_NEVER) { in virtio_fs_fill_super()
1572 if (ctx->dax_mode == FUSE_DAX_ALWAYS && !fs->dax_dev) { in virtio_fs_fill_super()
1573 err = -EINVAL; in virtio_fs_fill_super()
1574 pr_err("virtio-fs: dax can't be enabled as filesystem" in virtio_fs_fill_super()
1578 ctx->dax_dev = fs->dax_dev; in virtio_fs_fill_super()
1584 for (i = 0; i < fs->nvqs; i++) { in virtio_fs_fill_super()
1585 struct virtio_fs_vq *fsvq = &fs->vqs[i]; in virtio_fs_fill_super()
1587 fuse_dev_install(fsvq->fud, fc); in virtio_fs_fill_super()
1605 struct fuse_conn *fc = fm->fc; in virtio_fs_conn_destroy()
1606 struct virtio_fs *vfs = fc->iq.priv; in virtio_fs_conn_destroy()
1607 struct virtio_fs_vq *fsvq = &vfs->vqs[VQ_HIPRIO]; in virtio_fs_conn_destroy()
1616 spin_lock(&fsvq->lock); in virtio_fs_conn_destroy()
1617 fsvq->connected = false; in virtio_fs_conn_destroy()
1618 spin_unlock(&fsvq->lock); in virtio_fs_conn_destroy()
1639 if (sb->s_root) { in virtio_kill_sb()
1651 struct fuse_mount *fsc_fm = fsc->s_fs_info; in virtio_fs_test_super()
1654 return fsc_fm->fc->iq.priv == sb_fm->fc->iq.priv; in virtio_fs_test_super()
1664 int err = -EIO; in virtio_fs_get_tree()
1667 * in fc->iq->priv. Once fuse_conn is going away, it calls ->put() in virtio_fs_get_tree()
1670 fs = virtio_fs_find_instance(fsc->source); in virtio_fs_get_tree()
1672 pr_info("virtio-fs: tag <%s> not found\n", fsc->source); in virtio_fs_get_tree()
1673 return -EINVAL; in virtio_fs_get_tree()
1676 virtqueue_size = virtqueue_get_vring_size(fs->vqs[VQ_REQUEST].vq); in virtio_fs_get_tree()
1680 err = -ENOMEM; in virtio_fs_get_tree()
1689 fuse_conn_init(fc, fm, fsc->user_ns, &virtio_fs_fiq_ops, fs); in virtio_fs_get_tree()
1690 fc->release = fuse_free_conn; in virtio_fs_get_tree()
1691 fc->delete_stale = true; in virtio_fs_get_tree()
1692 fc->auto_submounts = true; in virtio_fs_get_tree()
1693 fc->sync_fs = true; in virtio_fs_get_tree()
1696 fc->max_pages_limit = min_t(unsigned int, fc->max_pages_limit, in virtio_fs_get_tree()
1697 virtqueue_size - FUSE_HEADER_OVERHEAD); in virtio_fs_get_tree()
1699 fsc->s_fs_info = fm; in virtio_fs_get_tree()
1701 if (fsc->s_fs_info) in virtio_fs_get_tree()
1706 if (!sb->s_root) { in virtio_fs_get_tree()
1713 sb->s_flags |= SB_ACTIVE; in virtio_fs_get_tree()
1716 WARN_ON(fsc->root); in virtio_fs_get_tree()
1717 fsc->root = dget(sb->s_root); in virtio_fs_get_tree()
1736 if (fsc->purpose == FS_CONTEXT_FOR_SUBMOUNT) in virtio_fs_init_fs_context()
1741 return -ENOMEM; in virtio_fs_init_fs_context()
1742 fsc->fs_private = ctx; in virtio_fs_init_fs_context()
1743 fsc->ops = &virtio_fs_context_ops; in virtio_fs_init_fs_context()
1759 add_uevent_var(env, "TAG=%s", fs->tag); in virtio_fs_uevent()
1772 return -ENOMEM; in virtio_fs_sysfs_init()