linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH, RFC] ext4: add ioctl to force 32-bit hashes from indexed dirs
@ 2013-03-28 16:14 Eric Sandeen
  2013-03-28 17:37 ` Bernd Schubert
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Eric Sandeen @ 2013-03-28 16:14 UTC (permalink / raw)
  To: ext4 development; +Cc: Anand Avati

This adds a new ioctl, EXT4_IOC_32BITHASH, which allows a
userspace application to request 32-bit rather than 64-bit
hashes from readdir on an indexed / dx / htree directory.

Gluster had been relying on the top bits of the d_off being
free; there are some reports that filling all 64 bits breaks
Samba as well.  The infrastructure to return 32-bit hashes
already exists; NFS can turn it on, and it's turned on for
32-bit processes as well.  So it's just a matter of flipping
on the f_mode flag before readdir starts.

Care needs to be taken that we don't change the FMODE flag
after readdir has been started, so we make sure that
filp->private_data has not yet been set before we set the flag
(Thanks Zach!).

Pre-submission-fixes-by: Zach Brown <zab@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---

diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c
index d8cd1f0..5e3a316 100644
--- a/fs/ext4/dir.c
+++ b/fs/ext4/dir.c
@@ -39,7 +39,7 @@ static int ext4_dx_readdir(struct file *filp,
  *
  * Return 1 if it is a dx dir, 0 if not
  */
-static int is_dx_dir(struct inode *inode)
+int is_dx_dir(struct inode *inode)
 {
 	struct super_block *sb = inode->i_sb;
 
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 3b83cd6..63e922e 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -614,6 +614,7 @@ enum {
  /* note ioctl 10 reserved for an early version of the FIEMAP ioctl */
  /* note ioctl 11 reserved for filesystem-independent FIEMAP ioctl */
 #define EXT4_IOC_ALLOC_DA_BLKS		_IO('f', 12)
+#define EXT4_IOC_32BITHASH		_IOW('f', 13, long)
 #define EXT4_IOC_MOVE_EXT		_IOWR('f', 15, struct move_extent)
 #define EXT4_IOC_RESIZE_FS		_IOW('f', 16, __u64)
 
@@ -1953,6 +1954,7 @@ extern unsigned ext4_num_overhead_clusters(struct super_block *sb,
 ext4_fsblk_t ext4_inode_to_goal_block(struct inode *);
 
 /* dir.c */
+extern int is_dx_dir(struct inode *inode);
 extern int __ext4_check_dir_entry(const char *, unsigned int, struct inode *,
 				  struct file *,
 				  struct ext4_dir_entry_2 *,
diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
index 721f4d3..f226373 100644
--- a/fs/ext4/ioctl.c
+++ b/fs/ext4/ioctl.c
@@ -356,7 +356,41 @@ group_add_out:
 		mnt_drop_write_file(filp);
 		return err;
 	}
+	case EXT4_IOC_32BITHASH: {
+		__u32 hash32bits;
+		int err = 0;
 
+		if (get_user(hash32bits, (int __user *) arg))
+			return -EFAULT;
+
+		/* Serialize with readdir */
+		if ((err = mutex_lock_killable(&inode->i_mutex)))
+			return err;
+
+		/* protect f_mode */
+		spin_lock(&filp->f_lock);
+
+		/* Only valid for htree directories */
+		if (!S_ISDIR(inode->i_mode) || !is_dx_dir(inode)) {
+			err = -EINVAL;
+			goto out_32bithash;
+		}
+
+		/* Have we already started readir on this dx dir? */
+		if (filp->private_data) {
+			err = -EINVAL;
+			goto out_32bithash;
+		}
+
+		if (hash32bits)
+			filp->f_mode |= FMODE_32BITHASH;
+		else
+			filp->f_mode &= ~FMODE_32BITHASH;
+out_32bithash:
+		spin_unlock(&filp->f_lock);
+		mutex_unlock(&inode->i_mutex);
+		return err;
+	}
 	case EXT4_IOC_RESIZE_FS: {
 		ext4_fsblk_t n_blocks_count;
 		struct super_block *sb = inode->i_sb;


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH, RFC] ext4: add ioctl to force 32-bit hashes from indexed dirs
  2013-03-28 16:14 [PATCH, RFC] ext4: add ioctl to force 32-bit hashes from indexed dirs Eric Sandeen
@ 2013-03-28 17:37 ` Bernd Schubert
  2013-03-28 20:25 ` Eric Sandeen
  2013-03-28 20:39 ` [PATCH, RFC V2] " Eric Sandeen
  2 siblings, 0 replies; 5+ messages in thread
From: Bernd Schubert @ 2013-03-28 17:37 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: ext4 development, Anand Avati

Hello Eric,

thanks, I'm going to review it thouroughly tomorrow again. Just noticed 
a small typo in a comment.

On 03/28/2013 05:14 PM, Eric Sandeen wrote:
> +		/* Have we already started readir on this dx dir? */
                                            ^^^^^^


Cheers,
Bernd

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH, RFC] ext4: add ioctl to force 32-bit hashes from indexed dirs
  2013-03-28 16:14 [PATCH, RFC] ext4: add ioctl to force 32-bit hashes from indexed dirs Eric Sandeen
  2013-03-28 17:37 ` Bernd Schubert
@ 2013-03-28 20:25 ` Eric Sandeen
  2013-03-28 20:39 ` [PATCH, RFC V2] " Eric Sandeen
  2 siblings, 0 replies; 5+ messages in thread
From: Eric Sandeen @ 2013-03-28 20:25 UTC (permalink / raw)
  To: ext4 development; +Cc: Anand Avati

On 3/28/13 11:14 AM, Eric Sandeen wrote:
> This adds a new ioctl, EXT4_IOC_32BITHASH, which allows a
> userspace application to request 32-bit rather than 64-bit
> hashes from readdir on an indexed / dx / htree directory.
> 
> Gluster had been relying on the top bits of the d_off being
> free; there are some reports that filling all 64 bits breaks
> Samba as well.  The infrastructure to return 32-bit hashes
> already exists; NFS can turn it on, and it's turned on for
> 32-bit processes as well.  So it's just a matter of flipping
> on the f_mode flag before readdir starts.
> 
> Care needs to be taken that we don't change the FMODE flag
> after readdir has been started, so we make sure that
> filp->private_data has not yet been set before we set the flag
> (Thanks Zach!).

Hm, it crosses my mind that the ability to send 0/1 to the
ioctl may be pointless, perhaps it should be an _IO not
_IOW; since once we have started readdir we will return
-EINVAL, I'm not sure we'd ever have occasion to
turn 32-bit hashing back "off."

-Eric

> Pre-submission-fixes-by: Zach Brown <zab@redhat.com>
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>
> ---
> 
> diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c
> index d8cd1f0..5e3a316 100644
> --- a/fs/ext4/dir.c
> +++ b/fs/ext4/dir.c
> @@ -39,7 +39,7 @@ static int ext4_dx_readdir(struct file *filp,
>   *
>   * Return 1 if it is a dx dir, 0 if not
>   */
> -static int is_dx_dir(struct inode *inode)
> +int is_dx_dir(struct inode *inode)
>  {
>  	struct super_block *sb = inode->i_sb;
>  
> diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
> index 3b83cd6..63e922e 100644
> --- a/fs/ext4/ext4.h
> +++ b/fs/ext4/ext4.h
> @@ -614,6 +614,7 @@ enum {
>   /* note ioctl 10 reserved for an early version of the FIEMAP ioctl */
>   /* note ioctl 11 reserved for filesystem-independent FIEMAP ioctl */
>  #define EXT4_IOC_ALLOC_DA_BLKS		_IO('f', 12)
> +#define EXT4_IOC_32BITHASH		_IOW('f', 13, long)
>  #define EXT4_IOC_MOVE_EXT		_IOWR('f', 15, struct move_extent)
>  #define EXT4_IOC_RESIZE_FS		_IOW('f', 16, __u64)
>  
> @@ -1953,6 +1954,7 @@ extern unsigned ext4_num_overhead_clusters(struct super_block *sb,
>  ext4_fsblk_t ext4_inode_to_goal_block(struct inode *);
>  
>  /* dir.c */
> +extern int is_dx_dir(struct inode *inode);
>  extern int __ext4_check_dir_entry(const char *, unsigned int, struct inode *,
>  				  struct file *,
>  				  struct ext4_dir_entry_2 *,
> diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
> index 721f4d3..f226373 100644
> --- a/fs/ext4/ioctl.c
> +++ b/fs/ext4/ioctl.c
> @@ -356,7 +356,41 @@ group_add_out:
>  		mnt_drop_write_file(filp);
>  		return err;
>  	}
> +	case EXT4_IOC_32BITHASH: {
> +		__u32 hash32bits;
> +		int err = 0;
>  
> +		if (get_user(hash32bits, (int __user *) arg))
> +			return -EFAULT;
> +
> +		/* Serialize with readdir */
> +		if ((err = mutex_lock_killable(&inode->i_mutex)))
> +			return err;
> +
> +		/* protect f_mode */
> +		spin_lock(&filp->f_lock);
> +
> +		/* Only valid for htree directories */
> +		if (!S_ISDIR(inode->i_mode) || !is_dx_dir(inode)) {
> +			err = -EINVAL;
> +			goto out_32bithash;
> +		}
> +
> +		/* Have we already started readir on this dx dir? */
> +		if (filp->private_data) {
> +			err = -EINVAL;
> +			goto out_32bithash;
> +		}
> +
> +		if (hash32bits)
> +			filp->f_mode |= FMODE_32BITHASH;
> +		else
> +			filp->f_mode &= ~FMODE_32BITHASH;
> +out_32bithash:
> +		spin_unlock(&filp->f_lock);
> +		mutex_unlock(&inode->i_mutex);
> +		return err;
> +	}
>  	case EXT4_IOC_RESIZE_FS: {
>  		ext4_fsblk_t n_blocks_count;
>  		struct super_block *sb = inode->i_sb;
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH, RFC V2] ext4: add ioctl to force 32-bit hashes from indexed dirs
  2013-03-28 16:14 [PATCH, RFC] ext4: add ioctl to force 32-bit hashes from indexed dirs Eric Sandeen
  2013-03-28 17:37 ` Bernd Schubert
  2013-03-28 20:25 ` Eric Sandeen
@ 2013-03-28 20:39 ` Eric Sandeen
  2013-04-01 15:35   ` [PATCH, RFC V3] " Eric Sandeen
  2 siblings, 1 reply; 5+ messages in thread
From: Eric Sandeen @ 2013-03-28 20:39 UTC (permalink / raw)
  To: ext4 development; +Cc: Anand Avati

This adds a new ioctl, EXT4_IOC_32BITHASH, which allows a
userspace application to request 32-bit rather than 64-bit
hashes from readdir on an indexed / dx / htree directory.

Gluster had been relying on the top bits of the d_off being
free; there are some reports that filling all 64 bits breaks
Samba as well.  The infrastructure to return 32-bit hashes
already exists; NFS can turn it on, and it's turned on for
32-bit processes as well.  So it's just a matter of flipping
on the f_mode flag before readdir starts.

Care needs to be taken that we don't change the FMODE flag
after readdir has been started, so we make sure that
filp->private_data has not yet been set before we set the flag.
(Thanks Zach!).

Pre-submission-fixes-by: Zach Brown <zab@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---

V2:
fix "readir" typo
rename goto target to *_out like others
remove parameter; we can't really ever turn this back off once it's used.
closing and reopening is the only way to get back to 64 bit hashes.

diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c
index d8cd1f0..5e3a316 100644
--- a/fs/ext4/dir.c
+++ b/fs/ext4/dir.c
@@ -39,7 +39,7 @@ static int ext4_dx_readdir(struct file *filp,
  *
  * Return 1 if it is a dx dir, 0 if not
  */
-static int is_dx_dir(struct inode *inode)
+int is_dx_dir(struct inode *inode)
 {
 	struct super_block *sb = inode->i_sb;
 
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 3b83cd6..44a9b52 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -614,6 +614,7 @@ enum {
  /* note ioctl 10 reserved for an early version of the FIEMAP ioctl */
  /* note ioctl 11 reserved for filesystem-independent FIEMAP ioctl */
 #define EXT4_IOC_ALLOC_DA_BLKS		_IO('f', 12)
+#define EXT4_IOC_32BITHASH		_IO('f', 13)
 #define EXT4_IOC_MOVE_EXT		_IOWR('f', 15, struct move_extent)
 #define EXT4_IOC_RESIZE_FS		_IOW('f', 16, __u64)
 
@@ -1953,6 +1954,7 @@ extern unsigned ext4_num_overhead_clusters(struct super_block *sb,
 ext4_fsblk_t ext4_inode_to_goal_block(struct inode *);
 
 /* dir.c */
+extern int is_dx_dir(struct inode *inode);
 extern int __ext4_check_dir_entry(const char *, unsigned int, struct inode *,
 				  struct file *,
 				  struct ext4_dir_entry_2 *,
diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
index 721f4d3..1d1f7f1 100644
--- a/fs/ext4/ioctl.c
+++ b/fs/ext4/ioctl.c
@@ -356,7 +356,34 @@ group_add_out:
 		mnt_drop_write_file(filp);
 		return err;
 	}
+	case EXT4_IOC_32BITHASH: {
+		int err = 0;
 
+		/* Serialize with readdir */
+		if ((err = mutex_lock_killable(&inode->i_mutex)))
+			return err;
+
+		/* protect f_mode */
+		spin_lock(&filp->f_lock);
+
+		/* Only valid for htree directories */
+		if (!S_ISDIR(inode->i_mode) || !is_dx_dir(inode)) {
+			err = -EINVAL;
+			goto hash32bits_out;
+		}
+
+		/* Have we already started readdir on this dx dir? */
+		if (filp->private_data) {
+			err = -EINVAL;
+			goto hash32bits_out;
+		}
+
+		filp->f_mode |= FMODE_32BITHASH;
+hash32bits_out:
+		spin_unlock(&filp->f_lock);
+		mutex_unlock(&inode->i_mutex);
+		return err;
+	}
 	case EXT4_IOC_RESIZE_FS: {
 		ext4_fsblk_t n_blocks_count;
 		struct super_block *sb = inode->i_sb;


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH, RFC V3] ext4: add ioctl to force 32-bit hashes from indexed dirs
  2013-03-28 20:39 ` [PATCH, RFC V2] " Eric Sandeen
@ 2013-04-01 15:35   ` Eric Sandeen
  0 siblings, 0 replies; 5+ messages in thread
From: Eric Sandeen @ 2013-04-01 15:35 UTC (permalink / raw)
  To: ext4 development; +Cc: Anand Avati

This adds a new ioctl, EXT4_IOC_32BITHASH, which allows a
userspace application to request 32-bit rather than 64-bit
hashes from readdir on an indexed / dx / htree directory.

Gluster had been relying on the top bits of the d_off being
free; there are some reports that filling all 64 bits breaks
Samba as well.  The infrastructure to return 32-bit hashes
already exists; NFS can turn it on, and it's turned on for
32-bit processes as well.  So it's just a matter of flipping
on the f_mode flag before readdir starts.

Care needs to be taken that we don't change the FMODE flag
after readdir has been started, so we make sure that
filp->private_data has not yet been set before we set the flag.
(Thanks Zach!).

Pre-submission-fixes-by: Zach Brown <zab@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---

V2:
fix "readir" typo
rename goto target to *_out like others
remove parameter; we can't really ever turn this back off once it's used.
closing and reopening is the only way to get back to 64 bit hashes.

V3:
return -ENOTDIR if the target is not a directory

diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c
index d8cd1f0..5e3a316 100644
--- a/fs/ext4/dir.c
+++ b/fs/ext4/dir.c
@@ -39,7 +39,7 @@ static int ext4_dx_readdir(struct file *filp,
  *
  * Return 1 if it is a dx dir, 0 if not
  */
-static int is_dx_dir(struct inode *inode)
+int is_dx_dir(struct inode *inode)
 {
 	struct super_block *sb = inode->i_sb;
 
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 3b83cd6..44a9b52 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -614,6 +614,7 @@ enum {
  /* note ioctl 10 reserved for an early version of the FIEMAP ioctl */
  /* note ioctl 11 reserved for filesystem-independent FIEMAP ioctl */
 #define EXT4_IOC_ALLOC_DA_BLKS		_IO('f', 12)
+#define EXT4_IOC_32BITHASH		_IO('f', 13)
 #define EXT4_IOC_MOVE_EXT		_IOWR('f', 15, struct move_extent)
 #define EXT4_IOC_RESIZE_FS		_IOW('f', 16, __u64)
 
@@ -1953,6 +1954,7 @@ extern unsigned ext4_num_overhead_clusters(struct super_block *sb,
 ext4_fsblk_t ext4_inode_to_goal_block(struct inode *);
 
 /* dir.c */
+extern int is_dx_dir(struct inode *inode);
 extern int __ext4_check_dir_entry(const char *, unsigned int, struct inode *,
 				  struct file *,
 				  struct ext4_dir_entry_2 *,
diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
index 721f4d3..4b1183a 100644
--- a/fs/ext4/ioctl.c
+++ b/fs/ext4/ioctl.c
@@ -356,7 +356,39 @@ group_add_out:
 		mnt_drop_write_file(filp);
 		return err;
 	}
+	case EXT4_IOC_32BITHASH: {
+		int err = 0;
 
+		/* Serialize with readdir */
+		if ((err = mutex_lock_killable(&inode->i_mutex)))
+			return err;
+
+		/* protect f_mode */
+		spin_lock(&filp->f_lock);
+
+		/* Only valid for htree directories */
+		if (!S_ISDIR(inode->i_mode)) {
+			err = -ENOTDIR;
+			goto hash32bits_out;
+		}
+
+		if (!is_dx_dir(inode)) {
+			err = -EINVAL;
+			goto hash32bits_out;
+		}
+
+		/* Have we already started readdir on this dx dir? */
+		if (filp->private_data) {
+			err = -EINVAL;
+			goto hash32bits_out;
+		}
+
+		filp->f_mode |= FMODE_32BITHASH;
+hash32bits_out:
+		spin_unlock(&filp->f_lock);
+		mutex_unlock(&inode->i_mutex);
+		return err;
+	}
 	case EXT4_IOC_RESIZE_FS: {
 		ext4_fsblk_t n_blocks_count;
 		struct super_block *sb = inode->i_sb;



^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-04-01 15:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-28 16:14 [PATCH, RFC] ext4: add ioctl to force 32-bit hashes from indexed dirs Eric Sandeen
2013-03-28 17:37 ` Bernd Schubert
2013-03-28 20:25 ` Eric Sandeen
2013-03-28 20:39 ` [PATCH, RFC V2] " Eric Sandeen
2013-04-01 15:35   ` [PATCH, RFC V3] " Eric Sandeen

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).