diff mbox

[26/27] fs: Provide __inode_get_bytes()

Message ID 20170816154127.7048-27-jack@suse.cz (mailing list archive)
State New, archived
Headers show

Commit Message

Jan Kara Aug. 16, 2017, 3:41 p.m. UTC
Provide helper __inode_get_bytes() which assumes i_lock is already
acquired. Quota code will need this to be able to use i_lock to protect
consistency of quota accounting information and inode usage.

Signed-off-by: Jan Kara <jack@suse.cz>
---
 fs/stat.c          | 2 +-
 include/linux/fs.h | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)

Comments

Andreas Dilger Aug. 16, 2017, 4:12 p.m. UTC | #1
On Aug 16, 2017, at 9:41 AM, Jan Kara <jack@suse.cz> wrote:
> 
> Provide helper __inode_get_bytes() which assumes i_lock is already
> acquired. Quota code will need this to be able to use i_lock to protect
> consistency of quota accounting information and inode usage.

Minor nit - it's better to give functions like this a useful name, like
inode_get_bytes_locked(), since "__" doesn't really convey any semantic info,
and also messes up function sorting order (e.g. tag completion on inode_get_bytes
will not show __inode_get_bytes() but would show inode_get_bytes_locked()).

Cheers, Andreas

> Signed-off-by: Jan Kara <jack@suse.cz>
> ---
> fs/stat.c          | 2 +-
> include/linux/fs.h | 4 ++++
> 2 files changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/stat.c b/fs/stat.c
> index c35610845ab1..8a6aa8caf891 100644
> --- a/fs/stat.c
> +++ b/fs/stat.c
> @@ -710,7 +710,7 @@ loff_t inode_get_bytes(struct inode *inode)
> 	loff_t ret;
> 
> 	spin_lock(&inode->i_lock);
> -	ret = (((loff_t)inode->i_blocks) << 9) + inode->i_bytes;
> +	ret = __inode_get_bytes(inode);
> 	spin_unlock(&inode->i_lock);
> 	return ret;
> }
> diff --git a/include/linux/fs.h b/include/linux/fs.h
> index 6e1fd5d21248..d6e9ab7f184f 100644
> --- a/include/linux/fs.h
> +++ b/include/linux/fs.h
> @@ -2998,6 +2998,10 @@ void __inode_add_bytes(struct inode *inode, loff_t bytes);
> void inode_add_bytes(struct inode *inode, loff_t bytes);
> void __inode_sub_bytes(struct inode *inode, loff_t bytes);
> void inode_sub_bytes(struct inode *inode, loff_t bytes);
> +static inline loff_t __inode_get_bytes(struct inode *inode)
> +{
> +	return (((loff_t)inode->i_blocks) << 9) + inode->i_bytes;
> +}
> loff_t inode_get_bytes(struct inode *inode);
> void inode_set_bytes(struct inode *inode, loff_t bytes);
> const char *simple_get_link(struct dentry *, struct inode *,
> --
> 2.12.3
> 


Cheers, Andreas
Jan Kara Aug. 17, 2017, 8:04 p.m. UTC | #2
On Wed 16-08-17 10:12:41, Andreas Dilger wrote:
> On Aug 16, 2017, at 9:41 AM, Jan Kara <jack@suse.cz> wrote:
> > 
> > Provide helper __inode_get_bytes() which assumes i_lock is already
> > acquired. Quota code will need this to be able to use i_lock to protect
> > consistency of quota accounting information and inode usage.
> 
> Minor nit - it's better to give functions like this a useful name, like
> inode_get_bytes_locked(), since "__" doesn't really convey any semantic info,
> and also messes up function sorting order (e.g. tag completion on inode_get_bytes
> will not show __inode_get_bytes() but would show inode_get_bytes_locked()).

Well, I did this to be consistent with __inode_add_bytes(),
__inode_sub_bytes(), etc.

								Honza

> 
> Cheers, Andreas
> 
> > Signed-off-by: Jan Kara <jack@suse.cz>
> > ---
> > fs/stat.c          | 2 +-
> > include/linux/fs.h | 4 ++++
> > 2 files changed, 5 insertions(+), 1 deletion(-)
> > 
> > diff --git a/fs/stat.c b/fs/stat.c
> > index c35610845ab1..8a6aa8caf891 100644
> > --- a/fs/stat.c
> > +++ b/fs/stat.c
> > @@ -710,7 +710,7 @@ loff_t inode_get_bytes(struct inode *inode)
> > 	loff_t ret;
> > 
> > 	spin_lock(&inode->i_lock);
> > -	ret = (((loff_t)inode->i_blocks) << 9) + inode->i_bytes;
> > +	ret = __inode_get_bytes(inode);
> > 	spin_unlock(&inode->i_lock);
> > 	return ret;
> > }
> > diff --git a/include/linux/fs.h b/include/linux/fs.h
> > index 6e1fd5d21248..d6e9ab7f184f 100644
> > --- a/include/linux/fs.h
> > +++ b/include/linux/fs.h
> > @@ -2998,6 +2998,10 @@ void __inode_add_bytes(struct inode *inode, loff_t bytes);
> > void inode_add_bytes(struct inode *inode, loff_t bytes);
> > void __inode_sub_bytes(struct inode *inode, loff_t bytes);
> > void inode_sub_bytes(struct inode *inode, loff_t bytes);
> > +static inline loff_t __inode_get_bytes(struct inode *inode)
> > +{
> > +	return (((loff_t)inode->i_blocks) << 9) + inode->i_bytes;
> > +}
> > loff_t inode_get_bytes(struct inode *inode);
> > void inode_set_bytes(struct inode *inode, loff_t bytes);
> > const char *simple_get_link(struct dentry *, struct inode *,
> > --
> > 2.12.3
> > 
> 
> 
> Cheers, Andreas
> 
> 
> 
> 
>
diff mbox

Patch

diff --git a/fs/stat.c b/fs/stat.c
index c35610845ab1..8a6aa8caf891 100644
--- a/fs/stat.c
+++ b/fs/stat.c
@@ -710,7 +710,7 @@  loff_t inode_get_bytes(struct inode *inode)
 	loff_t ret;
 
 	spin_lock(&inode->i_lock);
-	ret = (((loff_t)inode->i_blocks) << 9) + inode->i_bytes;
+	ret = __inode_get_bytes(inode);
 	spin_unlock(&inode->i_lock);
 	return ret;
 }
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 6e1fd5d21248..d6e9ab7f184f 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2998,6 +2998,10 @@  void __inode_add_bytes(struct inode *inode, loff_t bytes);
 void inode_add_bytes(struct inode *inode, loff_t bytes);
 void __inode_sub_bytes(struct inode *inode, loff_t bytes);
 void inode_sub_bytes(struct inode *inode, loff_t bytes);
+static inline loff_t __inode_get_bytes(struct inode *inode)
+{
+	return (((loff_t)inode->i_blocks) << 9) + inode->i_bytes;
+}
 loff_t inode_get_bytes(struct inode *inode);
 void inode_set_bytes(struct inode *inode, loff_t bytes);
 const char *simple_get_link(struct dentry *, struct inode *,