mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Howells <dhowells@redhat.com>
To: linux-fsdevel@vger.kernel.org, viro@ZenIV.linux.org.uk,
	valerie.aurora@gmail.com
Cc: linux-kernel@vger.kernel.org,
	David Howells <dhowells@redhat.com> (Further development)
Subject: [PATCH 67/73] ext2: Remove target inode pointer from ext2_add_entry() [ver #2]
Date: Tue, 21 Feb 2012 18:05:54 +0000	[thread overview]
Message-ID: <20120221180553.25235.8550.stgit@warthog.procyon.org.uk> (raw)
In-Reply-To: <20120221175721.25235.8901.stgit@warthog.procyon.org.uk>

ext2_add_entry() does not really need an inode pointer except to get at the
inode number and file mode that it contains.  Instead of passing in an inode
pointer, pass in the inode number and type to be recorded in the directory
entry.

ext2_add_link() can then calculate the directory entry type from the file mode
and pass it to ext2_add_entry().

Original-author: David Howells <dhowells@redhat.com>
Signed-off-by: David Howells <dhowells@redhat.com> (Further development)
---

 fs/ext2/dir.c |   64 +++++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 44 insertions(+), 20 deletions(-)

diff --git a/fs/ext2/dir.c b/fs/ext2/dir.c
index d8382dc..dcb2d64 100644
--- a/fs/ext2/dir.c
+++ b/fs/ext2/dir.c
@@ -282,13 +282,18 @@ static unsigned char ext2_type_by_mode[S_IFMT >> S_SHIFT] = {
 	[S_IFLNK >> S_SHIFT]	= EXT2_FT_SYMLINK,
 };
 
-static inline void ext2_set_de_type(ext2_dirent *de, struct inode *inode)
+static inline void ext2_set_de_type(ext2_dirent *de, struct super_block *sb,
+				    umode_t mode, unsigned char file_type)
 {
-	umode_t mode = inode->i_mode;
-	if (EXT2_HAS_INCOMPAT_FEATURE(inode->i_sb, EXT2_FEATURE_INCOMPAT_FILETYPE))
-		de->file_type = ext2_type_by_mode[(mode & S_IFMT)>>S_SHIFT];
-	else
+	if (!EXT2_HAS_INCOMPAT_FEATURE(sb, EXT2_FEATURE_INCOMPAT_FILETYPE)) {
 		de->file_type = 0;
+		return;
+	}
+
+	if (file_type)
+		de->file_type = file_type;
+	else
+		de->file_type = ext2_type_by_mode[(mode & S_IFMT) >> S_SHIFT];
 }
 
 static int
@@ -480,7 +485,7 @@ void ext2_set_link(struct inode *dir, struct ext2_dir_entry_2 *de,
 	err = ext2_prepare_chunk(page, pos, len);
 	BUG_ON(err);
 	de->inode = cpu_to_le32(inode->i_ino);
-	ext2_set_de_type(de, inode);
+	ext2_set_de_type(de, inode->i_sb, inode->i_mode, 0);
 	err = ext2_commit_chunk(page, pos, len);
 	ext2_put_page(page);
 	if (update_times)
@@ -489,7 +494,18 @@ void ext2_set_link(struct inode *dir, struct ext2_dir_entry_2 *de,
 	mark_inode_dirty(dir);
 }
 
-int ext2_add_entry(struct dentry *dentry, struct inode *inode)
+/*
+ * Called from three settings:
+ *
+ * - Creating a regular entry - de/page NULL, doesn't exist
+ * - Creating a fallthru - de/page NULL, doesn't exist
+ * - Creating a whiteout - de/page set if it exists
+ *
+ * @new_file_type is either EXT2_FT_WHT, EXT2_FT_FALLTHRU, or 0.  If
+ * 0, file type is determined by inode->i_mode.
+ */
+int ext2_add_entry(struct dentry *dentry, ino_t ino, umode_t mode,
+		   unsigned char new_file_type)
 {
 	struct inode *dir = dentry->d_parent->d_inode;
 	const char *name = dentry->d_name.name;
@@ -497,10 +513,10 @@ int ext2_add_entry(struct dentry *dentry, struct inode *inode)
 	unsigned chunk_size = ext2_chunk_size(dir);
 	unsigned reclen = EXT2_DIR_REC_LEN(namelen);
 	unsigned short rec_len, name_len;
-	struct page *page = NULL;
-	ext2_dirent * de;
 	unsigned long npages = dir_pages(dir);
 	unsigned long n;
+	ext2_dirent *de;
+	struct page *page;
 	char *kaddr;
 	loff_t pos;
 	int err;
@@ -530,6 +546,7 @@ int ext2_add_entry(struct dentry *dentry, struct inode *inode)
 				de->rec_len = ext2_rec_len_to_disk(chunk_size);
 				de->inode = 0;
 				de->file_type = 0;
+				printk("%s: allocated new de\n", dentry->d_name.name);
 				goto got_it;
 			}
 			if (de->rec_len == 0) {
@@ -538,15 +555,22 @@ int ext2_add_entry(struct dentry *dentry, struct inode *inode)
 				err = -EIO;
 				goto out_unlock;
 			}
-			err = -EEXIST;
-			if (ext2_match (namelen, name, de))
-				goto out_unlock;
 			name_len = EXT2_DIR_REC_LEN(de->name_len);
 			rec_len = ext2_rec_len_from_disk(de->rec_len);
-			if (!ext2_dirent_in_use(de) && rec_len >= reclen)
+			if (ext2_match(namelen, name, de)) {
+				err = -EEXIST;
+				/* XXX handle whiteouts and fallthroughs here */
+				printk("%s: found existing de\n", dentry->d_name.name);
+				goto got_it;
+			}
+			if (!ext2_dirent_in_use(de) && rec_len >= reclen) {
+				printk("%s: reusing empty de\n", dentry->d_name.name);
 				goto got_it;
-			if (rec_len >= name_len + reclen)
+			}
+			if (rec_len >= name_len + reclen) {
+				printk("%s: carving off end of in-use de\n", dentry->d_name.name);
 				goto got_it;
+			}
 			de = (ext2_dirent *) ((char *) de + rec_len);
 		}
 		unlock_page(page);
@@ -561,7 +585,7 @@ got_it:
 	err = ext2_prepare_chunk(page, pos, rec_len);
 	if (err)
 		goto out_unlock;
-	if (ext2_dirent_in_use(de)) {
+	if (ext2_dirent_in_use(de) && !ext2_match (namelen, name, de)) {
 		ext2_dirent *de1 = (ext2_dirent *) ((char *) de + name_len);
 		de1->rec_len = ext2_rec_len_to_disk(rec_len - name_len);
 		de->rec_len = ext2_rec_len_to_disk(name_len);
@@ -569,8 +593,8 @@ got_it:
 	}
 	de->name_len = namelen;
 	memcpy(de->name, name, namelen);
-	de->inode = cpu_to_le32(inode->i_ino);
-	ext2_set_de_type (de, inode);
+	de->inode = cpu_to_le32(ino);
+	ext2_set_de_type(de, dir->i_sb, mode, new_file_type);
 	err = ext2_commit_chunk(page, pos, rec_len);
 	dir->i_mtime = dir->i_ctime = CURRENT_TIME_SEC;
 	EXT2_I(dir)->i_flags &= ~EXT2_BTREE_FL;
@@ -587,7 +611,7 @@ out_unlock:
 
 int ext2_add_link(struct dentry *dentry, struct inode *inode)
 {
-	return ext2_add_entry(dentry, inode);
+	return ext2_add_entry(dentry, inode->i_ino, inode->i_mode, 0);
 }
 
 /*
@@ -660,14 +684,14 @@ int ext2_make_empty(struct inode *inode, struct inode *parent)
 	de->rec_len = ext2_rec_len_to_disk(EXT2_DIR_REC_LEN(1));
 	memcpy (de->name, ".\0\0", 4);
 	de->inode = cpu_to_le32(inode->i_ino);
-	ext2_set_de_type (de, inode);
+	ext2_set_de_type (de, inode->i_sb, inode->i_mode, 0);
 
 	de = (struct ext2_dir_entry_2 *)(kaddr + EXT2_DIR_REC_LEN(1));
 	de->name_len = 2;
 	de->rec_len = ext2_rec_len_to_disk(chunk_size - EXT2_DIR_REC_LEN(1));
 	de->inode = cpu_to_le32(parent->i_ino);
 	memcpy (de->name, "..\0", 4);
-	ext2_set_de_type (de, inode);
+	ext2_set_de_type (de, inode->i_sb, inode->i_mode, 0);
 	kunmap_atomic(kaddr, KM_USER0);
 	err = ext2_commit_chunk(page, 0, chunk_size);
 fail:


  parent reply	other threads:[~2012-02-21 20:02 UTC|newest]

Thread overview: 89+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-21 17:57 [RFC][PATCH 00/73] Union Mount " David Howells
2012-02-21 17:57 ` [PATCH 01/73] VFS: Make chown() and lchown() call fchownat() " David Howells
2012-02-21 17:57 ` [PATCH 02/73] VFS: Make clone_mnt()/copy_tree()/collect_mounts() return errors " David Howells
2012-02-21 17:57 ` [PATCH 03/73] VFS: Comment mount following code " David Howells
2012-02-21 17:57 ` [PATCH 04/73] VFS: Make lookup_hash() return a struct path " David Howells
2012-02-21 17:58 ` [PATCH 05/73] VFS: Pass mount flags to sget() " David Howells
2012-02-21 17:58 ` [PATCH 06/73] VFS: Split inode_permission() " David Howells
2012-02-21 17:58 ` [PATCH 07/73] VFS: Add hard read-only users count to superblock " David Howells
2012-02-21 17:58 ` [PATCH 08/73] VFS: Add CL_NO_SHARED flag to clone_mnt()/copy_tree() " David Howells
2012-02-29  6:56   ` Ram Pai
2012-02-21 17:58 ` [PATCH 09/73] VFS: Add CL_NO_SLAVE " David Howells
2012-02-29  6:58   ` Ram Pai
2012-02-21 17:58 ` [PATCH 10/73] VFS: Add CL_MAKE_HARD_READONLY " David Howells
2012-02-21 17:58 ` [PATCH 11/73] whiteout/NFSD: Don't return information about whiteouts to userspace " David Howells
2012-02-21 17:58 ` [PATCH 12/73] whiteout: Define flags and operations for opaque inodes " David Howells
2012-02-21 17:59 ` [PATCH 13/73] whiteout: Add vfs_whiteout() and whiteout inode operation " David Howells
2012-02-21 17:59 ` [PATCH 14/73] whiteout: Allow removal of a directory with whiteouts " David Howells
2012-02-21 17:59 ` [PATCH 15/73] tmpfs: Add whiteout support " David Howells
2012-02-21 17:59 ` [PATCH 16/73] VFS: Basic fallthru definitions " David Howells
2012-02-21 17:59 ` [PATCH 17/73] tmpfs: Add fallthru support " David Howells
2012-02-21 17:59 ` [PATCH 18/73] union-mount: Union mounts documentation " David Howells
2012-02-27  2:57   ` Randy Dunlap
2012-02-21 17:59 ` [PATCH 19/73] union-mount: Introduce MNT_UNION and MS_UNION flags " David Howells
2012-02-21 18:00 ` [PATCH 20/73] union-mount: Add CONFIG_UNION_MOUNT option " David Howells
2012-02-21 18:00 ` [PATCH 21/73] union-mount: Create union_stack structure " David Howells
2012-02-21 18:00 ` [PATCH 22/73] union-mount: Add two superblock fields for union mounts " David Howells
2012-02-21 18:00 ` [PATCH 23/73] union-mount: Add union_alloc() " David Howells
2012-02-21 18:00 ` [PATCH 24/73] union-mount: Add union_find_dir() " David Howells
2012-02-21 18:00 ` [PATCH 25/73] union-mount: Create d_free_unions() " David Howells
2012-02-21 18:00 ` [PATCH 26/73] union-mount: Free union stack on removal of topmost dentry from dcache " David Howells
2012-02-21 18:00 ` [PATCH 27/73] union-mount: Create union_add_dir() " David Howells
2012-02-21 18:01 ` [PATCH 28/73] union-mount: Add union_create_topmost_dir() " David Howells
2012-02-21 18:01 ` [PATCH 29/73] union-mount: Create IS_MNT_UNION() " David Howells
2012-02-21 18:01 ` [PATCH 30/73] union-mount: Create needs_lookup_union() " David Howells
2012-02-21 18:01 ` [PATCH 31/73] union-mount: Create check_topmost_union_mnt() " David Howells
2012-02-21 18:01 ` [PATCH 32/73] union-mount: Add clone_union_tree() and put_union_sb() " David Howells
2012-02-21 18:01 ` [PATCH 33/73] unionmount: Mark lower layers in union " David Howells
2012-02-21 18:01 ` [PATCH 34/73] union-mount: Create build_root_union() " David Howells
2012-02-21 18:01 ` [PATCH 35/73] union-mount: Create prepare_mnt_union() and cleanup_mnt_union() " David Howells
2012-02-21 18:02 ` [PATCH 36/73] union-mount: Prevent improper union-related remounts " David Howells
2012-02-21 18:02 ` [PATCH 37/73] union-mount: Prevent topmost file system from being mounted elsewhere " David Howells
2012-02-21 18:02 ` [PATCH 38/73] union-mount: Prevent bind mounts of union mounts " David Howells
2012-02-21 18:02 ` [PATCH 39/73] union-mount: Duplicate the i_{, dir_}mutex lock classes and use for upper layer " David Howells
2012-02-21 18:02 ` [PATCH 40/73] union-mount: Implement union mount " David Howells
2012-02-21 18:02 ` [PATCH 41/73] union-mount: Temporarily disable some syscalls " David Howells
2012-02-21 18:02 ` [PATCH 42/73] union-mount: Basic infrastructure of __lookup_union() " David Howells
2012-02-21 18:02 ` [PATCH 43/73] union-mount: Process negative dentries in " David Howells
2012-02-21 18:03 ` [PATCH 44/73] union-mount: Return files found in lower layers " David Howells
2012-02-21 18:03 ` [PATCH 45/73] union-mount: Build union stack " David Howells
2012-02-21 18:03 ` [PATCH 46/73] union-mount: Follow mount " David Howells
2012-02-21 18:03 ` [PATCH 47/73] union-mount: Add lookup_union_locked() " David Howells
2012-02-21 18:03 ` [PATCH 48/73] union-mount: Add wrapper for lookup_union_locked() and RCU hook " David Howells
2012-02-21 18:03 ` [PATCH 49/73] union-mount: Call union lookup functions in lookup path " David Howells
2012-02-21 18:03 ` [PATCH 50/73] union-mount: Create whiteout on unlink() " David Howells
2012-02-21 18:03 ` [PATCH 51/73] union-mount: Create whiteout on rmdir() " David Howells
2012-02-21 18:03 ` [PATCH 52/73] union-mount: Set opaque flag on new directories in unioned file systems " David Howells
2012-02-21 18:04 ` [PATCH 53/73] union-mount: Copy up directory entries on first readdir() " David Howells
2012-02-21 18:04 ` [PATCH 54/73] union-mount: Add generic_readdir_fallthru() helper " David Howells
2012-02-21 18:04 ` [PATCH 55/73] fallthru: tmpfs support for lookup of d_type/d_ino in fallthrus " David Howells
2012-02-21 18:04 ` [PATCH 56/73] union-mount: In-kernel file copyup routines " David Howells
2012-02-21 18:04 ` [PATCH 57/73] VFS: Create user_path_nd() to lookup both parent and target " David Howells
2012-02-21 18:04 ` [PATCH 58/73] unionmount: Add LOOKUP_COPY_UP " David Howells
2012-02-21 18:04 ` [PATCH 59/73] unionmount: Override creds when copying up a file to correctly set ownership " David Howells
2012-02-21 18:05 ` [PATCH 60/73] union-mount: Implement union-aware access()/faccessat() " David Howells
2012-02-21 18:05 ` [PATCH 61/73] union-mount: Make various syscalls aware (link, chmod, chown, utimes & setxattr) " David Howells
2012-02-21 18:05 ` [PATCH 62/73] union-mount: Implement union-aware rename() " David Howells
2012-02-21 18:05 ` [PATCH 63/73] union-mount: Implement union-aware writable open() " David Howells
2012-02-21 18:05 ` [PATCH 64/73] union-mount: Implement union-aware truncate() " David Howells
2012-02-21 18:05 ` [PATCH 65/73] ext2: Add ext2_dirent_in_use() " David Howells
2012-02-21 18:05 ` [PATCH 66/73] ext2: Split ext2_add_entry() from ext2_add_link() " David Howells
2012-02-27  0:04   ` Ted Ts'o
2012-02-27  3:30     ` Andreas Dilger
2012-02-27 19:09       ` Ted Ts'o
2012-02-27 20:45         ` Andreas Dilger
2012-02-21 18:05 ` David Howells [this message]
2012-02-27  0:22   ` [PATCH 67/73] ext2: Remove target inode pointer from ext2_add_entry() " Ted Ts'o
2012-02-21 18:06 ` [PATCH 68/73] ext2: Add whiteout and opaque directory support " David Howells
2012-02-21 18:06 ` [PATCH 69/73] ext2: Add fallthru " David Howells
2012-02-27  0:33   ` Ted Ts'o
2012-02-21 18:06 ` [PATCH 70/73] fallthru: ext2 support for lookup of d_type/d_ino in fallthrus " David Howells
2012-02-21 18:06 ` [PATCH 71/73] jffs2: Add whiteout support " David Howells
2012-02-21 18:06 ` [PATCH 72/73] jffs2: Add fallthru " David Howells
2012-02-21 18:06 ` [PATCH 73/73] fallthru: jffs2 support for lookup of d_type/d_ino in fallthrus " David Howells
2012-02-26  6:48 ` copy-up xattr (Re: [RFC][PATCH 00/73] Union Mount [ver #2]) J. R. Okajima
2012-03-26 14:22 ` David Howells
2012-03-27  4:38   ` Casey Schaufler
2012-03-27 13:10     ` David Quigley
2012-03-27 16:37       ` Casey Schaufler
2012-03-28 14:51   ` J. R. Okajima

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=20120221180553.25235.8550.stgit@warthog.procyon.org.uk \
    --to=dhowells@redhat.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=valerie.aurora@gmail.com \
    --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

all inboxes | Powered by JetHome®