linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Vivek Goyal <vgoyal@redhat.com>
To: Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
	hch@lst.de, virtio-fs@redhat.com,
	v9fs-developer@lists.sourceforge.net, stefanha@redhat.com,
	miklos@szeredi.hu
Subject: Re: [PATCH v3 3/3] fs: simplify get_filesystem_list / get_all_fs_names
Date: Fri, 30 Jul 2021 08:24:18 -0400	[thread overview]
Message-ID: <YQPvcilZ09yByXb5@redhat.com> (raw)
In-Reply-To: <YQNOY9H/6mJMWRNN@zeniv-ca.linux.org.uk>

On Fri, Jul 30, 2021 at 12:57:07AM +0000, Al Viro wrote:
> On Wed, Jul 14, 2021 at 04:23:21PM -0400, Vivek Goyal wrote:
> 
> > +static int __init split_fs_names(char *page, char *names)
> >  {
> > +	int count = 0;
> > +	char *p = page;
> >  
> > +	strcpy(p, root_fs_names);
> > +	while (*p++) {
> > +		if (p[-1] == ',')
> > +			p[-1] = '\0';
> >  	}
> > +	*p = '\0';
> > +
> > +	for (p = page; *p; p += strlen(p)+1)
> > +		count++;
> >  
> > +	return count;
> >  }
> 
> Ummm....  The last part makes no sense - it counts '\0' in the array
> pointed to be page, until the first double '\0' in there.  All of
> which had been put there by the loop immediately prior to that one...

I want split_fs_names() to replace ',' with space as well as return
number of null terminated strings found. So first loop just replaces
',' with '\0' and second loop counts number of strings.

Previously split_fs_names() was only replacing ',' with '\0'. Now
we are changing the semantics and returning number of strings
left in the buffer after the replacement.

I initilaly thought that if I can manage it with single loop but
there were quite a few corner cases. So I decided to use two
loops instead. One for replacement and one for counting.

> 
> Incidentally, it treats stray ,, in root_fs_names as termination;
> is that intentional?

Just trying to keep the existing behavior. Existing get_fs_names(), also
replaces all instances of ',' with '\0'. So if there are two consecutive,
',', that will result in two consecutive '\0' and caller will view
it as end of buffer. 

IOW, rootfsnames=foo,,bar will effectively be treated as "rootfsname=foo".

That's the current behavior and I did not try to improve on it just
keeps on increasing the size of patches. That's probably an improvement
for some other day if somebody cares.

Thanks
Vivek


  reply	other threads:[~2021-07-30 12:28 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-14 20:23 [PATCH v3 0/3] support booting of arbitrary non-blockdevice file systems Vivek Goyal
2021-07-14 20:23 ` [PATCH v3 1/3] init: split get_fs_names Vivek Goyal
2021-07-15 10:04   ` Stefan Hajnoczi
2021-07-14 20:23 ` [PATCH v3 2/3] init: allow mounting arbitrary non-blockdevice filesystems as root Vivek Goyal
2021-07-15 10:04   ` Stefan Hajnoczi
2021-07-14 20:23 ` [PATCH v3 3/3] fs: simplify get_filesystem_list / get_all_fs_names Vivek Goyal
2021-07-21 15:46   ` Stefan Hajnoczi
2021-07-30  0:57   ` Al Viro
2021-07-30 12:24     ` Vivek Goyal [this message]
2021-07-27 18:29 ` [PATCH v3 0/3] support booting of arbitrary non-blockdevice file systems Vivek Goyal
2021-07-29 15:08 ` Christian Brauner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YQPvcilZ09yByXb5@redhat.com \
    --to=vgoyal@redhat.com \
    --cc=hch@lst.de \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=stefanha@redhat.com \
    --cc=v9fs-developer@lists.sourceforge.net \
    --cc=viro@zeniv.linux.org.uk \
    --cc=virtio-fs@redhat.com \
    --subject='Re: [PATCH v3 3/3] fs: simplify get_filesystem_list / get_all_fs_names' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).