Re: Question about sg_count_fuse_req() in linux/fs/fuse/virtio_fs.c

From: Connor Kuehl
Date: Thu Mar 18 2021 - 09:59:44 EST

On 3/18/21 8:56 AM, Vivek Goyal wrote:
I think all the in args are being mapped into a single scatter gather
element and that's why it does not matter whether in_numargs is 3, 2 or 1.
They will be mapped in a single element.

len = fuse_len_args(numargs - argpages, args);
if (len)
sg_init_one(&sg[total_sgs++], argbuf, len);

out_sgs += sg_init_fuse_args(&sg[out_sgs], req,
(struct fuse_arg *)args->in_args,
args->in_numargs, args->in_pages,
req->argbuf, &argbuf_used);

When we are sending some data in some pages, then we set args->in_pages
to true. And in that case, last element of args->in_args[] contains the
total size of bytes in additional pages we are sending and is not part
of in_args being mapped to scatter gather element. That's why this

if (args->in_numargs - args->in_pages)
total_sgs += 1;

Aha! Thank you, Vivek. That makes sense.

Not sure when we will have a case where args->in_numargs = 1 and
args->in_pages=true. Do we ever hit that.

Not in my experience. My previous mail was examining this routine mainly in a vacuum.



Especially since the block right below it counts pages if args->in_pages is

if (args->in_pages) {
size = args->in_args[args->in_numargs - 1].size;
total_sgs += sg_count_fuse_pages(ap->descs, ap->num_pages,

The rest of the routine goes on similarly but for the 'out' components.

I doubt incrementing 'total_sgs' in the first if-statement I showed above is
vestigial, I just think my mental model of what is happening here is

Any clarification is much appreciated!