linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Amir Goldstein <amir73il@gmail.com>
To: "Theodore Ts'o" <tytso@mit.edu>
Cc: Dave Chinner <david@fromorbit.com>,
	"Darrick J. Wong" <darrick.wong@oracle.com>,
	Jan Kara <jack@suse.com>, Chris Mason <clm@fb.com>,
	Boaz Harrosh <boaz@plexistor.com>,
	Jaegeuk Kim <jaegeuk@kernel.org>,
	Ryusuke Konishi <konishi.ryusuke@lab.ntt.co.jp>,
	Mark Fasheh <mfasheh@versity.com>,
	Evgeniy Dushistov <dushistov@mail.ru>,
	Miklos Szeredi <miklos@szeredi.hu>,
	Al Viro <viro@zeniv.linux.org.uk>,
	linux-fsdevel <linux-fsdevel@vger.kernel.org>
Subject: Re: [RFC][PATCH 11/11] xfs: use common file type conversion
Date: Wed, 21 Dec 2016 18:37:42 +0200	[thread overview]
Message-ID: <CAOQ4uxjnUNQWiwx_rExePs_S_eTZWbVkqY1UgBUzbehKn4LxWQ@mail.gmail.com> (raw)
In-Reply-To: <20161221150619.hkgsqwcdzkqlum4v@thunk.org>

On Wed, Dec 21, 2016 at 5:06 PM, Theodore Ts'o <tytso@mit.edu> wrote:
...

>
> The fact that the three bit encoding of the directory file types is
> fully defined, and can *not* ever be extended without breaking things
> means that the chances that it would be a problem is much less.  So I
> don't object quite as much as Dave and Darrick --- but I'll also point
> out the benefits are quite small.  All we are saving is 16 bytes per
> file system compiled into the kernel.
>
> So it's a lot of discussion / changes for very little gain.
>

Right. never claimed that saving data segment space is the issue
here. To be completely honest, I started looking at ways to optimize
whiteout iteration and was appalled to see all that code copy&paste,
so went on an OCD cleanup spree.

So it is really a lot more about clumsiness of the current code then
about saving actual lines on code or space in data segment.

Perhaps I should have settled with defining this common section:

+#define S_DT_SHIFT     12
+#define S_DT(mode)     (((mode) & S_IFMT) >> S_DT_SHIFT)
+#define S_DT_MASK      (S_IFMT >> S_DT_SHIFT)
+
+#define DT_UNKNOWN     0
+#define DT_FIFO                S_DT(S_IFIFO) /* 1 */
+#define DT_CHR         S_DT(S_IFCHR) /* 2 */
+#define DT_DIR         S_DT(S_IFDIR) /* 4 */
+#define DT_BLK         S_DT(S_IFBLK) /* 6 */
+#define DT_REG         S_DT(S_IFREG) /* 8 */
+#define DT_LNK         S_DT(S_IFLNK) /* 10 */
+#define DT_SOCK                S_DT(S_IFSOCK) /* 12 */
+#define DT_WHT         14
+
+#define DT_MAX         (S_DT_MASK + 1) /* 16 */

and using S_DT(mode) and DT_MAX in place of all the many places in the
code that open code the >> S_SHIFT.

Note that all those file system copy&pasted a potential bug.

This is an array of size 15:

static unsigned char ext2_type_by_mode[S_IFMT >> S_SHIFT] = {

and it is always addressed this way:

ext2_type_by_mode[(inode->i_mode & S_IFMT)>>S_SHIFT];

Which *can* try to address ext2_type_by_mode[15]

Now, can you say for certain that you can never get a malformed i_mode
with ((inode->i_mode & S_IFMT) == S_IFMT) either from disk or from
some code calling into VFS functions, which do not sanity check the
file type of the mode argument.

Regardless, setting an array size of 15 is just as buggy as setting an
array size of DT_SOCK+1 (13) because no syscall sets a larger value
for the type bits.


>> The way we normally handle this is a method callout of some kind
>> into the filesystem to do the filesystem specific function, and
>> if there are multiple filesystems that do the same thing, they use a
>> common function. So that part of the patchset - providing common
>> helpers to inode mode/filesytem d_type conversion - is fine.
>
> The common helpers are inline functions that do an array lookup.  If
> we provide some other more generic way of letting the file systems
> provide conversion functions, at that point we're not really saving
> anything, and just adding complexity for no real benefit.
>

You are absolutely right. Not sure if you replied after seeing
v2 of this patch, but I did not use any fs provided complex conversion
functions.

I left the XFS code mostly as it was (same complexity) and sorted
it out to use some common defines and helpers in a way that
seem cleaner to me. At least that minor bug has been addressed.

I could further simplify the patch to use the S_DT(mode) macro
instead of the fs_umode_to_ftype(mode) helper.
If I do that, then the small snippet above that defines S_DT()
and DT_MAX is the only code that needs to be carried from
linux/fs.h to xfsprogs for building libxfs (same goes for e2fsprogs).

That's would be a technical code cleanup that does not mess
with on-disk format definitions.
I will send out an ext4 sample patch for you to consider.

Thanks for the feedback,
Amir.

  reply	other threads:[~2016-12-21 16:37 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-19 20:10 [RFC][PATCH 00/11] common implementation of dirent file types Amir Goldstein
2016-12-19 20:10 ` [RFC][PATCH 01/11] fs: common implementation of file type conversions Amir Goldstein
2016-12-19 21:13   ` Darrick J. Wong
2016-12-20  5:01     ` Amir Goldstein
2016-12-20  7:37   ` [RFC][PATCH v2 " Amir Goldstein
2016-12-19 20:10 ` [RFC][PATCH 02/11] ufs: use fs_umode_to_dtype() helper Amir Goldstein
2016-12-19 20:11 ` [RFC][PATCH 03/11] hfsplus: " Amir Goldstein
2016-12-19 20:11 ` [RFC][PATCH 04/11] ext2: use common file type conversion Amir Goldstein
2016-12-19 20:11 ` [RFC][PATCH 05/11] exofs: " Amir Goldstein
2016-12-19 21:50   ` Boaz Harrosh
2016-12-19 20:11 ` [RFC][PATCH 06/11] ext4: " Amir Goldstein
2016-12-19 20:11 ` [RFC][PATCH 07/11] ocfs2: " Amir Goldstein
2016-12-19 20:11 ` [RFC][PATCH 08/11] f2fs: " Amir Goldstein
2016-12-19 20:11 ` [RFC][PATCH 09/11] nilfs2: " Amir Goldstein
2016-12-19 20:11 ` [RFC][PATCH 10/11] btrfs: " Amir Goldstein
2016-12-19 20:11 ` [RFC][PATCH 11/11] xfs: " Amir Goldstein
2016-12-19 21:55   ` Darrick J. Wong
2016-12-20  6:17     ` Amir Goldstein
2016-12-20 14:07       ` Amir Goldstein
2016-12-20  0:28   ` Darrick J. Wong
2016-12-20  5:20     ` Amir Goldstein
2016-12-21  5:23       ` Dave Chinner
2016-12-21  6:37         ` Amir Goldstein
2016-12-21 10:12           ` [RFC][PATCH v2 " Amir Goldstein
2016-12-21 18:01             ` [PATCH v3 " Amir Goldstein
2016-12-22 21:07               ` [PATCH v4] xfs: fix the size of xfs_mode_to_ftype table Amir Goldstein
2016-12-23 21:01                 ` Darrick J. Wong
2016-12-24  7:31                   ` Amir Goldstein
2016-12-24 14:11                 ` Brian Foster
2016-12-21 15:06         ` [RFC][PATCH 11/11] xfs: use common file type conversion Theodore Ts'o
2016-12-21 16:37           ` Amir Goldstein [this message]
2016-12-21 22:56             ` Theodore Ts'o
2016-12-22  5:54               ` Amir Goldstein
2016-12-22 20:30                 ` Amir Goldstein
2016-12-21 16:59           ` Miklos Szeredi

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=CAOQ4uxjnUNQWiwx_rExePs_S_eTZWbVkqY1UgBUzbehKn4LxWQ@mail.gmail.com \
    --to=amir73il@gmail.com \
    --cc=boaz@plexistor.com \
    --cc=clm@fb.com \
    --cc=darrick.wong@oracle.com \
    --cc=david@fromorbit.com \
    --cc=dushistov@mail.ru \
    --cc=jack@suse.com \
    --cc=jaegeuk@kernel.org \
    --cc=konishi.ryusuke@lab.ntt.co.jp \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=mfasheh@versity.com \
    --cc=miklos@szeredi.hu \
    --cc=tytso@mit.edu \
    --cc=viro@zeniv.linux.org.uk \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).