Lines Matching +full:fiq +full:- +full:device
1 // SPDX-License-Identifier: GPL-2.0
3 * virtio-fs: Virtio Filesystem
28 /* List of virtio-fs device instances and a lock for the list. Also provides
29 * mutual exclusion in device removal and mounting path
41 /* Per-virtqueue state */
44 struct virtqueue *vq; /* protected by ->lock */
56 /* A virtio-fs device instance */
114 struct fuse_fs_context *ctx = fsc->fs_private; in virtio_fs_parse_param()
123 ctx->dax_mode = FUSE_DAX_ALWAYS; in virtio_fs_parse_param()
126 ctx->dax_mode = result.uint_32; in virtio_fs_parse_param()
129 return -EINVAL; in virtio_fs_parse_param()
137 struct fuse_fs_context *ctx = fsc->fs_private; in virtio_fs_free_fsc()
144 struct virtio_fs *fs = vq->vdev->priv; in vq_to_fsvq()
146 return &fs->vqs[vq->index]; in vq_to_fsvq()
149 /* Should be called with fsvq->lock held. */
152 fsvq->in_flight++; in inc_in_flight_req()
155 /* Should be called with fsvq->lock held. */
158 WARN_ON(fsvq->in_flight <= 0); in dec_in_flight_req()
159 fsvq->in_flight--; in dec_in_flight_req()
160 if (!fsvq->in_flight) in dec_in_flight_req()
161 complete(&fsvq->in_flight_zero); in dec_in_flight_req()
168 kfree(vfs->vqs); in release_virtio_fs_obj()
175 kref_put(&fs->refcount, release_virtio_fs_obj); in virtio_fs_put()
178 static void virtio_fs_fiq_release(struct fuse_iqueue *fiq) in virtio_fs_fiq_release() argument
180 struct virtio_fs *vfs = fiq->priv; in virtio_fs_fiq_release()
189 WARN_ON(fsvq->in_flight < 0); in virtio_fs_drain_queue()
192 spin_lock(&fsvq->lock); in virtio_fs_drain_queue()
193 if (fsvq->in_flight) { in virtio_fs_drain_queue()
197 reinit_completion(&fsvq->in_flight_zero); in virtio_fs_drain_queue()
198 spin_unlock(&fsvq->lock); in virtio_fs_drain_queue()
199 wait_for_completion(&fsvq->in_flight_zero); in virtio_fs_drain_queue()
201 spin_unlock(&fsvq->lock); in virtio_fs_drain_queue()
204 flush_work(&fsvq->done_work); in virtio_fs_drain_queue()
205 flush_delayed_work(&fsvq->dispatch_work); in virtio_fs_drain_queue()
213 for (i = 0; i < fs->nvqs; i++) { in virtio_fs_drain_all_queues_locked()
214 fsvq = &fs->vqs[i]; in virtio_fs_drain_all_queues_locked()
221 /* Provides mutual exclusion between ->remove and ->kill_sb in virtio_fs_drain_all_queues()
237 for (i = 0; i < fs->nvqs; i++) { in virtio_fs_start_all_queues()
238 fsvq = &fs->vqs[i]; in virtio_fs_start_all_queues()
239 spin_lock(&fsvq->lock); in virtio_fs_start_all_queues()
240 fsvq->connected = true; in virtio_fs_start_all_queues()
241 spin_unlock(&fsvq->lock); in virtio_fs_start_all_queues()
245 /* Add a new instance to the list or return -EEXIST if tag name exists*/
254 if (strcmp(fs->tag, fs2->tag) == 0) in virtio_fs_add_instance()
259 list_add_tail(&fs->list, &virtio_fs_instances); in virtio_fs_add_instance()
264 return -EEXIST; in virtio_fs_add_instance()
276 if (strcmp(fs->tag, tag) == 0) { in virtio_fs_find_instance()
277 kref_get(&fs->refcount); in virtio_fs_find_instance()
294 for (i = 0; i < fs->nvqs; i++) { in virtio_fs_free_devs()
295 struct virtio_fs_vq *fsvq = &fs->vqs[i]; in virtio_fs_free_devs()
297 if (!fsvq->fud) in virtio_fs_free_devs()
300 fuse_dev_free(fsvq->fud); in virtio_fs_free_devs()
301 fsvq->fud = NULL; in virtio_fs_free_devs()
305 /* Read filesystem name from virtio config into fs->tag (must kfree()). */
316 return -EINVAL; /* empty tag */ in virtio_fs_read_tag()
320 len = end - tag_buf; in virtio_fs_read_tag()
321 fs->tag = devm_kmalloc(&vdev->dev, len + 1, GFP_KERNEL); in virtio_fs_read_tag()
322 if (!fs->tag) in virtio_fs_read_tag()
323 return -ENOMEM; in virtio_fs_read_tag()
324 memcpy(fs->tag, tag_buf, len); in virtio_fs_read_tag()
325 fs->tag[len] = '\0'; in virtio_fs_read_tag()
334 struct virtqueue *vq = fsvq->vq; in virtio_fs_hiprio_done_work()
337 spin_lock(&fsvq->lock); in virtio_fs_hiprio_done_work()
349 spin_unlock(&fsvq->lock); in virtio_fs_hiprio_done_work()
359 pr_debug("virtio-fs: worker %s called.\n", __func__); in virtio_fs_request_dispatch_work()
361 spin_lock(&fsvq->lock); in virtio_fs_request_dispatch_work()
362 req = list_first_entry_or_null(&fsvq->end_reqs, struct fuse_req, in virtio_fs_request_dispatch_work()
365 spin_unlock(&fsvq->lock); in virtio_fs_request_dispatch_work()
369 list_del_init(&req->list); in virtio_fs_request_dispatch_work()
370 spin_unlock(&fsvq->lock); in virtio_fs_request_dispatch_work()
376 spin_lock(&fsvq->lock); in virtio_fs_request_dispatch_work()
377 req = list_first_entry_or_null(&fsvq->queued_reqs, in virtio_fs_request_dispatch_work()
380 spin_unlock(&fsvq->lock); in virtio_fs_request_dispatch_work()
383 list_del_init(&req->list); in virtio_fs_request_dispatch_work()
384 spin_unlock(&fsvq->lock); in virtio_fs_request_dispatch_work()
388 if (ret == -ENOMEM || ret == -ENOSPC) { in virtio_fs_request_dispatch_work()
389 spin_lock(&fsvq->lock); in virtio_fs_request_dispatch_work()
390 list_add_tail(&req->list, &fsvq->queued_reqs); in virtio_fs_request_dispatch_work()
391 schedule_delayed_work(&fsvq->dispatch_work, in virtio_fs_request_dispatch_work()
393 spin_unlock(&fsvq->lock); in virtio_fs_request_dispatch_work()
396 req->out.h.error = ret; in virtio_fs_request_dispatch_work()
397 spin_lock(&fsvq->lock); in virtio_fs_request_dispatch_work()
399 spin_unlock(&fsvq->lock); in virtio_fs_request_dispatch_work()
400 pr_err("virtio-fs: virtio_fs_enqueue_req() failed %d\n", in virtio_fs_request_dispatch_work()
419 struct virtio_fs_forget_req *req = &forget->req; in send_forget_request()
421 spin_lock(&fsvq->lock); in send_forget_request()
422 if (!fsvq->connected) { in send_forget_request()
430 vq = fsvq->vq; in send_forget_request()
431 dev_dbg(&vq->vdev->dev, "%s\n", __func__); in send_forget_request()
435 if (ret == -ENOMEM || ret == -ENOSPC) { in send_forget_request()
436 pr_debug("virtio-fs: Could not queue FORGET: err=%d. Will try later\n", in send_forget_request()
438 list_add_tail(&forget->list, &fsvq->queued_reqs); in send_forget_request()
439 schedule_delayed_work(&fsvq->dispatch_work, in send_forget_request()
446 pr_debug("virtio-fs: Could not queue FORGET: err=%d. Dropping it.\n", in send_forget_request()
458 spin_unlock(&fsvq->lock); in send_forget_request()
464 spin_unlock(&fsvq->lock); in send_forget_request()
473 pr_debug("virtio-fs: worker %s called.\n", __func__); in virtio_fs_hiprio_dispatch_work()
475 spin_lock(&fsvq->lock); in virtio_fs_hiprio_dispatch_work()
476 forget = list_first_entry_or_null(&fsvq->queued_reqs, in virtio_fs_hiprio_dispatch_work()
479 spin_unlock(&fsvq->lock); in virtio_fs_hiprio_dispatch_work()
483 list_del(&forget->list); in virtio_fs_hiprio_dispatch_work()
484 spin_unlock(&fsvq->lock); in virtio_fs_hiprio_dispatch_work()
490 /* Allocate and copy args into req->argbuf */
493 struct fuse_args *args = req->args; in copy_args_to_argbuf()
500 num_in = args->in_numargs - args->in_pages; in copy_args_to_argbuf()
501 num_out = args->out_numargs - args->out_pages; in copy_args_to_argbuf()
502 len = fuse_len_args(num_in, (struct fuse_arg *) args->in_args) + in copy_args_to_argbuf()
503 fuse_len_args(num_out, args->out_args); in copy_args_to_argbuf()
505 req->argbuf = kmalloc(len, GFP_ATOMIC); in copy_args_to_argbuf()
506 if (!req->argbuf) in copy_args_to_argbuf()
507 return -ENOMEM; in copy_args_to_argbuf()
510 memcpy(req->argbuf + offset, in copy_args_to_argbuf()
511 args->in_args[i].value, in copy_args_to_argbuf()
512 args->in_args[i].size); in copy_args_to_argbuf()
513 offset += args->in_args[i].size; in copy_args_to_argbuf()
519 /* Copy args out of and free req->argbuf */
528 remaining = req->out.h.len - sizeof(req->out.h); in copy_args_from_argbuf()
529 num_in = args->in_numargs - args->in_pages; in copy_args_from_argbuf()
530 num_out = args->out_numargs - args->out_pages; in copy_args_from_argbuf()
531 offset = fuse_len_args(num_in, (struct fuse_arg *)args->in_args); in copy_args_from_argbuf()
534 unsigned int argsize = args->out_args[i].size; in copy_args_from_argbuf()
536 if (args->out_argvar && in copy_args_from_argbuf()
537 i == args->out_numargs - 1 && in copy_args_from_argbuf()
542 memcpy(args->out_args[i].value, req->argbuf + offset, argsize); in copy_args_from_argbuf()
545 if (i != args->out_numargs - 1) in copy_args_from_argbuf()
546 remaining -= argsize; in copy_args_from_argbuf()
549 /* Store the actual size of the variable-length arg */ in copy_args_from_argbuf()
550 if (args->out_argvar) in copy_args_from_argbuf()
551 args->out_args[args->out_numargs - 1].size = remaining; in copy_args_from_argbuf()
553 kfree(req->argbuf); in copy_args_from_argbuf()
554 req->argbuf = NULL; in copy_args_from_argbuf()
561 struct fuse_pqueue *fpq = &fsvq->fud->pq; in virtio_fs_request_complete()
571 args = req->args; in virtio_fs_request_complete()
574 if (args->out_pages && args->page_zeroing) { in virtio_fs_request_complete()
575 len = args->out_args[args->out_numargs - 1].size; in virtio_fs_request_complete()
577 for (i = 0; i < ap->num_pages; i++) { in virtio_fs_request_complete()
578 thislen = ap->descs[i].length; in virtio_fs_request_complete()
580 WARN_ON(ap->descs[i].offset); in virtio_fs_request_complete()
581 page = ap->pages[i]; in virtio_fs_request_complete()
585 len -= thislen; in virtio_fs_request_complete()
590 spin_lock(&fpq->lock); in virtio_fs_request_complete()
591 clear_bit(FR_SENT, &req->flags); in virtio_fs_request_complete()
592 spin_unlock(&fpq->lock); in virtio_fs_request_complete()
595 spin_lock(&fsvq->lock); in virtio_fs_request_complete()
597 spin_unlock(&fsvq->lock); in virtio_fs_request_complete()
605 virtio_fs_request_complete(w->req, w->fsvq); in virtio_fs_complete_req_work()
613 struct fuse_pqueue *fpq = &fsvq->fud->pq; in virtio_fs_requests_done_work()
614 struct virtqueue *vq = fsvq->vq; in virtio_fs_requests_done_work()
621 spin_lock(&fsvq->lock); in virtio_fs_requests_done_work()
626 spin_lock(&fpq->lock); in virtio_fs_requests_done_work()
627 list_move_tail(&req->list, &reqs); in virtio_fs_requests_done_work()
628 spin_unlock(&fpq->lock); in virtio_fs_requests_done_work()
631 spin_unlock(&fsvq->lock); in virtio_fs_requests_done_work()
635 list_del_init(&req->list); in virtio_fs_requests_done_work()
638 if (req->args->may_block) { in virtio_fs_requests_done_work()
642 INIT_WORK(&w->done_work, virtio_fs_complete_req_work); in virtio_fs_requests_done_work()
643 w->fsvq = fsvq; in virtio_fs_requests_done_work()
644 w->req = req; in virtio_fs_requests_done_work()
645 schedule_work(&w->done_work); in virtio_fs_requests_done_work()
657 dev_dbg(&vq->vdev->dev, "%s %s\n", __func__, fsvq->name); in virtio_fs_vq_done()
659 schedule_work(&fsvq->done_work); in virtio_fs_vq_done()
665 strscpy(fsvq->name, name, VQ_NAME_LEN); in virtio_fs_init_vq()
666 spin_lock_init(&fsvq->lock); in virtio_fs_init_vq()
667 INIT_LIST_HEAD(&fsvq->queued_reqs); in virtio_fs_init_vq()
668 INIT_LIST_HEAD(&fsvq->end_reqs); in virtio_fs_init_vq()
669 init_completion(&fsvq->in_flight_zero); in virtio_fs_init_vq()
672 INIT_WORK(&fsvq->done_work, virtio_fs_requests_done_work); in virtio_fs_init_vq()
673 INIT_DELAYED_WORK(&fsvq->dispatch_work, in virtio_fs_init_vq()
676 INIT_WORK(&fsvq->done_work, virtio_fs_hiprio_done_work); in virtio_fs_init_vq()
677 INIT_DELAYED_WORK(&fsvq->dispatch_work, in virtio_fs_init_vq()
693 &fs->num_request_queues); in virtio_fs_setup_vqs()
694 if (fs->num_request_queues == 0) in virtio_fs_setup_vqs()
695 return -EINVAL; in virtio_fs_setup_vqs()
697 fs->nvqs = VQ_REQUEST + fs->num_request_queues; in virtio_fs_setup_vqs()
698 fs->vqs = kcalloc(fs->nvqs, sizeof(fs->vqs[VQ_HIPRIO]), GFP_KERNEL); in virtio_fs_setup_vqs()
699 if (!fs->vqs) in virtio_fs_setup_vqs()
700 return -ENOMEM; in virtio_fs_setup_vqs()
702 vqs = kmalloc_array(fs->nvqs, sizeof(vqs[VQ_HIPRIO]), GFP_KERNEL); in virtio_fs_setup_vqs()
703 callbacks = kmalloc_array(fs->nvqs, sizeof(callbacks[VQ_HIPRIO]), in virtio_fs_setup_vqs()
705 names = kmalloc_array(fs->nvqs, sizeof(names[VQ_HIPRIO]), GFP_KERNEL); in virtio_fs_setup_vqs()
707 ret = -ENOMEM; in virtio_fs_setup_vqs()
713 virtio_fs_init_vq(&fs->vqs[VQ_HIPRIO], "hiprio", VQ_HIPRIO); in virtio_fs_setup_vqs()
714 names[VQ_HIPRIO] = fs->vqs[VQ_HIPRIO].name; in virtio_fs_setup_vqs()
717 for (i = VQ_REQUEST; i < fs->nvqs; i++) { in virtio_fs_setup_vqs()
720 snprintf(vq_name, VQ_NAME_LEN, "requests.%u", i - VQ_REQUEST); in virtio_fs_setup_vqs()
721 virtio_fs_init_vq(&fs->vqs[i], vq_name, VQ_REQUEST); in virtio_fs_setup_vqs()
723 names[i] = fs->vqs[i].name; in virtio_fs_setup_vqs()
726 ret = virtio_find_vqs(vdev, fs->nvqs, vqs, callbacks, names, NULL); in virtio_fs_setup_vqs()
730 for (i = 0; i < fs->nvqs; i++) in virtio_fs_setup_vqs()
731 fs->vqs[i].vq = vqs[i]; in virtio_fs_setup_vqs()
739 kfree(fs->vqs); in virtio_fs_setup_vqs()
743 /* Free virtqueues (device must already be reset) */
746 vdev->config->del_vqs(vdev); in virtio_fs_cleanup_vqs()
759 size_t max_nr_pages = fs->window_len / PAGE_SIZE - pgoff; in virtio_fs_direct_access()
762 *kaddr = fs->window_kaddr + offset; in virtio_fs_direct_access()
764 *pfn = phys_to_pfn_t(fs->window_phys_addr + offset, in virtio_fs_direct_access()
811 dev_notice(&vdev->dev, "%s: No cache capability\n", __func__); in virtio_fs_setup_dax()
815 if (!devm_request_mem_region(&vdev->dev, cache_reg.addr, cache_reg.len, in virtio_fs_setup_dax()
816 dev_name(&vdev->dev))) { in virtio_fs_setup_dax()
817 dev_warn(&vdev->dev, "could not reserve region addr=0x%llx len=0x%llx\n", in virtio_fs_setup_dax()
819 return -EBUSY; in virtio_fs_setup_dax()
822 dev_notice(&vdev->dev, "Cache len: 0x%llx @ 0x%llx\n", cache_reg.len, in virtio_fs_setup_dax()
825 pgmap = devm_kzalloc(&vdev->dev, sizeof(*pgmap), GFP_KERNEL); in virtio_fs_setup_dax()
827 return -ENOMEM; in virtio_fs_setup_dax()
829 pgmap->type = MEMORY_DEVICE_FS_DAX; in virtio_fs_setup_dax()
836 pgmap->range = (struct range) { in virtio_fs_setup_dax()
838 .end = (phys_addr_t) cache_reg.addr + cache_reg.len - 1, in virtio_fs_setup_dax()
840 pgmap->nr_range = 1; in virtio_fs_setup_dax()
842 fs->window_kaddr = devm_memremap_pages(&vdev->dev, pgmap); in virtio_fs_setup_dax()
843 if (IS_ERR(fs->window_kaddr)) in virtio_fs_setup_dax()
844 return PTR_ERR(fs->window_kaddr); in virtio_fs_setup_dax()
846 fs->window_phys_addr = (phys_addr_t) cache_reg.addr; in virtio_fs_setup_dax()
847 fs->window_len = (phys_addr_t) cache_reg.len; in virtio_fs_setup_dax()
849 dev_dbg(&vdev->dev, "%s: window kaddr 0x%px phys_addr 0x%llx len 0x%llx\n", in virtio_fs_setup_dax()
850 __func__, fs->window_kaddr, cache_reg.addr, cache_reg.len); in virtio_fs_setup_dax()
852 fs->dax_dev = alloc_dax(fs, &virtio_fs_dax_ops); in virtio_fs_setup_dax()
853 if (IS_ERR(fs->dax_dev)) in virtio_fs_setup_dax()
854 return PTR_ERR(fs->dax_dev); in virtio_fs_setup_dax()
856 return devm_add_action_or_reset(&vdev->dev, virtio_fs_cleanup_dax, in virtio_fs_setup_dax()
857 fs->dax_dev); in virtio_fs_setup_dax()
867 return -ENOMEM; in virtio_fs_probe()
868 kref_init(&fs->refcount); in virtio_fs_probe()
869 vdev->priv = fs; in virtio_fs_probe()
885 /* Bring the device online in case the filesystem is mounted and in virtio_fs_probe()
899 kfree(fs->vqs); in virtio_fs_probe()
902 vdev->priv = NULL; in virtio_fs_probe()
912 for (i = 0; i < fs->nvqs; i++) { in virtio_fs_stop_all_queues()
913 fsvq = &fs->vqs[i]; in virtio_fs_stop_all_queues()
914 spin_lock(&fsvq->lock); in virtio_fs_stop_all_queues()
915 fsvq->connected = false; in virtio_fs_stop_all_queues()
916 spin_unlock(&fsvq->lock); in virtio_fs_stop_all_queues()
922 struct virtio_fs *fs = vdev->priv; in virtio_fs_remove()
925 /* This device is going away. No one should get new reference */ in virtio_fs_remove()
926 list_del_init(&fs->list); in virtio_fs_remove()
932 vdev->priv = NULL; in virtio_fs_remove()
933 /* Put device reference on virtio_fs object */ in virtio_fs_remove()
942 pr_warn("virtio-fs: suspend/resume not yet supported\n"); in virtio_fs_freeze()
943 return -EOPNOTSUPP; in virtio_fs_freeze()
974 static void virtio_fs_wake_forget_and_unlock(struct fuse_iqueue *fiq) in virtio_fs_wake_forget_and_unlock() argument
975 __releases(fiq->lock) in virtio_fs_wake_forget_and_unlock()
984 link = fuse_dequeue_forget(fiq, 1, NULL); in virtio_fs_wake_forget_and_unlock()
985 unique = fuse_get_unique(fiq); in virtio_fs_wake_forget_and_unlock()
987 fs = fiq->priv; in virtio_fs_wake_forget_and_unlock()
988 fsvq = &fs->vqs[VQ_HIPRIO]; in virtio_fs_wake_forget_and_unlock()
989 spin_unlock(&fiq->lock); in virtio_fs_wake_forget_and_unlock()
993 req = &forget->req; in virtio_fs_wake_forget_and_unlock()
995 req->ih = (struct fuse_in_header){ in virtio_fs_wake_forget_and_unlock()
997 .nodeid = link->forget_one.nodeid, in virtio_fs_wake_forget_and_unlock()
1001 req->arg = (struct fuse_forget_in){ in virtio_fs_wake_forget_and_unlock()
1002 .nlookup = link->forget_one.nlookup, in virtio_fs_wake_forget_and_unlock()
1009 static void virtio_fs_wake_interrupt_and_unlock(struct fuse_iqueue *fiq) in virtio_fs_wake_interrupt_and_unlock() argument
1010 __releases(fiq->lock) in virtio_fs_wake_interrupt_and_unlock()
1019 spin_unlock(&fiq->lock); in virtio_fs_wake_interrupt_and_unlock()
1022 /* Count number of scatter-gather elements required */
1032 total_len -= this_len; in sg_count_fuse_pages()
1038 /* Return the number of scatter-gather list elements required */
1041 struct fuse_args *args = req->args; in sg_count_fuse_req()
1045 if (args->in_numargs - args->in_pages) in sg_count_fuse_req()
1048 if (args->in_pages) { in sg_count_fuse_req()
1049 size = args->in_args[args->in_numargs - 1].size; in sg_count_fuse_req()
1050 total_sgs += sg_count_fuse_pages(ap->descs, ap->num_pages, in sg_count_fuse_req()
1054 if (!test_bit(FR_ISREPLY, &req->flags)) in sg_count_fuse_req()
1059 if (args->out_numargs - args->out_pages) in sg_count_fuse_req()
1062 if (args->out_pages) { in sg_count_fuse_req()
1063 size = args->out_args[args->out_numargs - 1].size; in sg_count_fuse_req()
1064 total_sgs += sg_count_fuse_pages(ap->descs, ap->num_pages, in sg_count_fuse_req()
1071 /* Add pages to scatter-gather list and return number of elements used */
1085 total_len -= this_len; in sg_init_fuse_pages()
1091 /* Add args to scatter-gather list and return number of elements used */
1100 struct fuse_args_pages *ap = container_of(req->args, typeof(*ap), args); in sg_init_fuse_args()
1104 len = fuse_len_args(numargs - argpages, args); in sg_init_fuse_args()
1110 ap->pages, ap->descs, in sg_init_fuse_args()
1111 ap->num_pages, in sg_init_fuse_args()
1112 args[numargs - 1].size); in sg_init_fuse_args()
1120 /* Add a request to a virtqueue and kick the device */
1130 struct fuse_args *args = req->args; in virtio_fs_enqueue_req()
1146 ret = -ENOMEM; in virtio_fs_enqueue_req()
1157 sg_init_one(&sg[out_sgs++], &req->in.h, sizeof(req->in.h)); in virtio_fs_enqueue_req()
1159 (struct fuse_arg *)args->in_args, in virtio_fs_enqueue_req()
1160 args->in_numargs, args->in_pages, in virtio_fs_enqueue_req()
1161 req->argbuf, &argbuf_used); in virtio_fs_enqueue_req()
1164 if (test_bit(FR_ISREPLY, &req->flags)) { in virtio_fs_enqueue_req()
1166 &req->out.h, sizeof(req->out.h)); in virtio_fs_enqueue_req()
1168 args->out_args, args->out_numargs, in virtio_fs_enqueue_req()
1169 args->out_pages, in virtio_fs_enqueue_req()
1170 req->argbuf + argbuf_used, NULL); in virtio_fs_enqueue_req()
1178 spin_lock(&fsvq->lock); in virtio_fs_enqueue_req()
1180 if (!fsvq->connected) { in virtio_fs_enqueue_req()
1181 spin_unlock(&fsvq->lock); in virtio_fs_enqueue_req()
1182 ret = -ENOTCONN; in virtio_fs_enqueue_req()
1186 vq = fsvq->vq; in virtio_fs_enqueue_req()
1189 spin_unlock(&fsvq->lock); in virtio_fs_enqueue_req()
1194 fpq = &fsvq->fud->pq; in virtio_fs_enqueue_req()
1195 spin_lock(&fpq->lock); in virtio_fs_enqueue_req()
1196 list_add_tail(&req->list, fpq->processing); in virtio_fs_enqueue_req()
1197 spin_unlock(&fpq->lock); in virtio_fs_enqueue_req()
1198 set_bit(FR_SENT, &req->flags); in virtio_fs_enqueue_req()
1206 spin_unlock(&fsvq->lock); in virtio_fs_enqueue_req()
1212 if (ret < 0 && req->argbuf) { in virtio_fs_enqueue_req()
1213 kfree(req->argbuf); in virtio_fs_enqueue_req()
1214 req->argbuf = NULL; in virtio_fs_enqueue_req()
1224 static void virtio_fs_wake_pending_and_unlock(struct fuse_iqueue *fiq) in virtio_fs_wake_pending_and_unlock() argument
1225 __releases(fiq->lock) in virtio_fs_wake_pending_and_unlock()
1233 WARN_ON(list_empty(&fiq->pending)); in virtio_fs_wake_pending_and_unlock()
1234 req = list_last_entry(&fiq->pending, struct fuse_req, list); in virtio_fs_wake_pending_and_unlock()
1235 clear_bit(FR_PENDING, &req->flags); in virtio_fs_wake_pending_and_unlock()
1236 list_del_init(&req->list); in virtio_fs_wake_pending_and_unlock()
1237 WARN_ON(!list_empty(&fiq->pending)); in virtio_fs_wake_pending_and_unlock()
1238 spin_unlock(&fiq->lock); in virtio_fs_wake_pending_and_unlock()
1240 fs = fiq->priv; in virtio_fs_wake_pending_and_unlock()
1243 __func__, req->in.h.opcode, req->in.h.unique, in virtio_fs_wake_pending_and_unlock()
1244 req->in.h.nodeid, req->in.h.len, in virtio_fs_wake_pending_and_unlock()
1245 fuse_len_args(req->args->out_numargs, req->args->out_args)); in virtio_fs_wake_pending_and_unlock()
1247 fsvq = &fs->vqs[queue_id]; in virtio_fs_wake_pending_and_unlock()
1250 if (ret == -ENOMEM || ret == -ENOSPC) { in virtio_fs_wake_pending_and_unlock()
1253 * context as we might be holding fc->bg_lock. in virtio_fs_wake_pending_and_unlock()
1255 spin_lock(&fsvq->lock); in virtio_fs_wake_pending_and_unlock()
1256 list_add_tail(&req->list, &fsvq->queued_reqs); in virtio_fs_wake_pending_and_unlock()
1258 schedule_delayed_work(&fsvq->dispatch_work, in virtio_fs_wake_pending_and_unlock()
1260 spin_unlock(&fsvq->lock); in virtio_fs_wake_pending_and_unlock()
1263 req->out.h.error = ret; in virtio_fs_wake_pending_and_unlock()
1264 pr_err("virtio-fs: virtio_fs_enqueue_req() failed %d\n", ret); in virtio_fs_wake_pending_and_unlock()
1267 spin_lock(&fsvq->lock); in virtio_fs_wake_pending_and_unlock()
1268 list_add_tail(&req->list, &fsvq->end_reqs); in virtio_fs_wake_pending_and_unlock()
1269 schedule_delayed_work(&fsvq->dispatch_work, 0); in virtio_fs_wake_pending_and_unlock()
1270 spin_unlock(&fsvq->lock); in virtio_fs_wake_pending_and_unlock()
1284 ctx->rootmode = S_IFDIR; in virtio_fs_ctx_set_defaults()
1285 ctx->default_permissions = 1; in virtio_fs_ctx_set_defaults()
1286 ctx->allow_other = 1; in virtio_fs_ctx_set_defaults()
1287 ctx->max_read = UINT_MAX; in virtio_fs_ctx_set_defaults()
1288 ctx->blksize = 512; in virtio_fs_ctx_set_defaults()
1289 ctx->destroy = true; in virtio_fs_ctx_set_defaults()
1290 ctx->no_control = true; in virtio_fs_ctx_set_defaults()
1291 ctx->no_force_umount = true; in virtio_fs_ctx_set_defaults()
1297 struct fuse_conn *fc = fm->fc; in virtio_fs_fill_super()
1298 struct virtio_fs *fs = fc->iq.priv; in virtio_fs_fill_super()
1299 struct fuse_fs_context *ctx = fsc->fs_private; in virtio_fs_fill_super()
1306 /* After holding mutex, make sure virtiofs device is still there. in virtio_fs_fill_super()
1307 * Though we are holding a reference to it, drive ->remove might in virtio_fs_fill_super()
1310 err = -EINVAL; in virtio_fs_fill_super()
1311 if (list_empty(&fs->list)) { in virtio_fs_fill_super()
1312 pr_info("virtio-fs: tag <%s> not found\n", fs->tag); in virtio_fs_fill_super()
1316 err = -ENOMEM; in virtio_fs_fill_super()
1318 for (i = 0; i < fs->nvqs; i++) { in virtio_fs_fill_super()
1319 struct virtio_fs_vq *fsvq = &fs->vqs[i]; in virtio_fs_fill_super()
1321 fsvq->fud = fuse_dev_alloc(); in virtio_fs_fill_super()
1322 if (!fsvq->fud) in virtio_fs_fill_super()
1327 ctx->fudptr = NULL; in virtio_fs_fill_super()
1328 if (ctx->dax_mode != FUSE_DAX_NEVER) { in virtio_fs_fill_super()
1329 if (ctx->dax_mode == FUSE_DAX_ALWAYS && !fs->dax_dev) { in virtio_fs_fill_super()
1330 err = -EINVAL; in virtio_fs_fill_super()
1331 pr_err("virtio-fs: dax can't be enabled as filesystem" in virtio_fs_fill_super()
1332 " device does not support it.\n"); in virtio_fs_fill_super()
1335 ctx->dax_dev = fs->dax_dev; in virtio_fs_fill_super()
1341 for (i = 0; i < fs->nvqs; i++) { in virtio_fs_fill_super()
1342 struct virtio_fs_vq *fsvq = &fs->vqs[i]; in virtio_fs_fill_super()
1344 fuse_dev_install(fsvq->fud, fc); in virtio_fs_fill_super()
1362 struct fuse_conn *fc = fm->fc; in virtio_fs_conn_destroy()
1363 struct virtio_fs *vfs = fc->iq.priv; in virtio_fs_conn_destroy()
1364 struct virtio_fs_vq *fsvq = &vfs->vqs[VQ_HIPRIO]; in virtio_fs_conn_destroy()
1373 spin_lock(&fsvq->lock); in virtio_fs_conn_destroy()
1374 fsvq->connected = false; in virtio_fs_conn_destroy()
1375 spin_unlock(&fsvq->lock); in virtio_fs_conn_destroy()
1396 if (sb->s_root) { in virtio_kill_sb()
1408 struct fuse_mount *fsc_fm = fsc->s_fs_info; in virtio_fs_test_super()
1411 return fsc_fm->fc->iq.priv == sb_fm->fc->iq.priv; in virtio_fs_test_super()
1421 int err = -EIO; in virtio_fs_get_tree()
1424 * in fc->iq->priv. Once fuse_conn is going away, it calls ->put() in virtio_fs_get_tree()
1427 fs = virtio_fs_find_instance(fsc->source); in virtio_fs_get_tree()
1429 pr_info("virtio-fs: tag <%s> not found\n", fsc->source); in virtio_fs_get_tree()
1430 return -EINVAL; in virtio_fs_get_tree()
1433 virtqueue_size = virtqueue_get_vring_size(fs->vqs[VQ_REQUEST].vq); in virtio_fs_get_tree()
1437 err = -ENOMEM; in virtio_fs_get_tree()
1446 fuse_conn_init(fc, fm, fsc->user_ns, &virtio_fs_fiq_ops, fs); in virtio_fs_get_tree()
1447 fc->release = fuse_free_conn; in virtio_fs_get_tree()
1448 fc->delete_stale = true; in virtio_fs_get_tree()
1449 fc->auto_submounts = true; in virtio_fs_get_tree()
1450 fc->sync_fs = true; in virtio_fs_get_tree()
1453 fc->max_pages_limit = min_t(unsigned int, fc->max_pages_limit, in virtio_fs_get_tree()
1454 virtqueue_size - FUSE_HEADER_OVERHEAD); in virtio_fs_get_tree()
1456 fsc->s_fs_info = fm; in virtio_fs_get_tree()
1458 if (fsc->s_fs_info) in virtio_fs_get_tree()
1463 if (!sb->s_root) { in virtio_fs_get_tree()
1470 sb->s_flags |= SB_ACTIVE; in virtio_fs_get_tree()
1473 WARN_ON(fsc->root); in virtio_fs_get_tree()
1474 fsc->root = dget(sb->s_root); in virtio_fs_get_tree()
1495 if (fsc->purpose == FS_CONTEXT_FOR_SUBMOUNT) in virtio_fs_init_fs_context()
1500 return -ENOMEM; in virtio_fs_init_fs_context()
1501 fsc->fs_private = ctx; in virtio_fs_init_fs_context()
1502 fsc->ops = &virtio_fs_context_ops; in virtio_fs_init_fs_context()