Re: [PATCH 01/11] quota: add wrapper function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue 05-10-10 22:20:17, Dmitry Monakhov wrote:
> This helps us to make code more readable.
  Well, wrappers aren't bad but if there's too many of them, things become
too obscured... But in this case I agree that the expression is common
enough to warrant a wrapper. It's just that the name "dq_opt" more suggest
to me some property of dquot itself, rather than a per-sb structure. A
better naming to me would be for example:
dqopt(sb) - returns quota_info structure of the superblock
sb_dqopt(dquot) - returns quota_info structure of the superblock dquot
  belongs to...

  Also with this naming it's clearer that these two functions return the same
thing, just for different types of objects.

								Honza
 
> Signed-off-by: Dmitry Monakhov <dmonakhov@xxxxxxxxx>
> ---
>  fs/ext3/super.c          |    2 +-
>  fs/ext4/super.c          |    2 +-
>  fs/ocfs2/quota_global.c  |    4 ++--
>  fs/quota/dquot.c         |   18 +++++++++---------
>  fs/quota/quota_tree.c    |    2 +-
>  fs/quota/quota_v1.c      |    8 ++++----
>  include/linux/quota.h    |    1 +
>  include/linux/quotaops.h |    4 ++++
>  8 files changed, 23 insertions(+), 18 deletions(-)
> 
> diff --git a/fs/ext3/super.c b/fs/ext3/super.c
> index 15f63d3..c5b0c1d 100644
> --- a/fs/ext3/super.c
> +++ b/fs/ext3/super.c
> @@ -2751,7 +2751,7 @@ static int ext3_statfs (struct dentry * dentry, struct kstatfs * buf)
>  
>  static inline struct inode *dquot_to_inode(struct dquot *dquot)
>  {
> -	return sb_dqopt(dquot->dq_sb)->files[dquot->dq_type];
> +	return dq_opt(dquot)->files[dquot->dq_type];
>  }
>  
>  static int ext3_write_dquot(struct dquot *dquot)
> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> index bcf86b3..301462a 100644
> --- a/fs/ext4/super.c
> +++ b/fs/ext4/super.c
> @@ -3968,7 +3968,7 @@ static int ext4_statfs(struct dentry *dentry, struct kstatfs *buf)
>  
>  static inline struct inode *dquot_to_inode(struct dquot *dquot)
>  {
> -	return sb_dqopt(dquot->dq_sb)->files[dquot->dq_type];
> +	return dq_opt(dquot)->files[dquot->dq_type];
>  }
>  
>  static int ext4_write_dquot(struct dquot *dquot)
> diff --git a/fs/ocfs2/quota_global.c b/fs/ocfs2/quota_global.c
> index 4607923..2c88a87 100644
> --- a/fs/ocfs2/quota_global.c
> +++ b/fs/ocfs2/quota_global.c
> @@ -657,9 +657,9 @@ static int ocfs2_write_dquot(struct dquot *dquot)
>  		mlog_errno(status);
>  		goto out;
>  	}
> -	mutex_lock(&sb_dqopt(dquot->dq_sb)->dqio_mutex);
> +	mutex_lock(&dq_opt(dqopt)->dqio_mutex);
>  	status = ocfs2_local_write_dquot(dquot);
> -	mutex_unlock(&sb_dqopt(dquot->dq_sb)->dqio_mutex);
> +	mutex_unlock(&dq_opt(dqopt)->dqio_mutex);
>  	ocfs2_commit_trans(osb, handle);
>  out:
>  	mlog_exit(status);
> diff --git a/fs/quota/dquot.c b/fs/quota/dquot.c
> index 686c2b7..ce542e2 100644
> --- a/fs/quota/dquot.c
> +++ b/fs/quota/dquot.c
> @@ -346,7 +346,7 @@ int dquot_mark_dquot_dirty(struct dquot *dquot)
>  
>  	spin_lock(&dq_list_lock);
>  	if (!test_and_set_bit(DQ_MOD_B, &dquot->dq_flags)) {
> -		list_add(&dquot->dq_dirty, &sb_dqopt(dquot->dq_sb)->
> +		list_add(&dquot->dq_dirty, &dq_opt(dquot)->
>  				info[dquot->dq_type].dqi_dirty_list);
>  		ret = 0;
>  	}
> @@ -401,7 +401,7 @@ EXPORT_SYMBOL(mark_info_dirty);
>  int dquot_acquire(struct dquot *dquot)
>  {
>  	int ret = 0, ret2 = 0;
> -	struct quota_info *dqopt = sb_dqopt(dquot->dq_sb);
> +	struct quota_info *dqopt = dq_opt(dquot);
>  
>  	mutex_lock(&dquot->dq_lock);
>  	mutex_lock(&dqopt->dqio_mutex);
> @@ -439,7 +439,7 @@ EXPORT_SYMBOL(dquot_acquire);
>  int dquot_commit(struct dquot *dquot)
>  {
>  	int ret = 0, ret2 = 0;
> -	struct quota_info *dqopt = sb_dqopt(dquot->dq_sb);
> +	struct quota_info *dqopt = dq_opt(dquot);
>  
>  	mutex_lock(&dqopt->dqio_mutex);
>  	spin_lock(&dq_list_lock);
> @@ -471,7 +471,7 @@ EXPORT_SYMBOL(dquot_commit);
>  int dquot_release(struct dquot *dquot)
>  {
>  	int ret = 0, ret2 = 0;
> -	struct quota_info *dqopt = sb_dqopt(dquot->dq_sb);
> +	struct quota_info *dqopt = dq_opt(dquot);
>  
>  	mutex_lock(&dquot->dq_lock);
>  	/* Check whether we are not racing with some other dqget() */
> @@ -1081,7 +1081,7 @@ void dquot_free_reserved_space(struct dquot *dquot, qsize_t number)
>  
>  static void dquot_decr_inodes(struct dquot *dquot, qsize_t number)
>  {
> -	if (sb_dqopt(dquot->dq_sb)->flags & DQUOT_NEGATIVE_USAGE ||
> +	if (dq_opt(dquot)->flags & DQUOT_NEGATIVE_USAGE ||
>  	    dquot->dq_dqb.dqb_curinodes >= number)
>  		dquot->dq_dqb.dqb_curinodes -= number;
>  	else
> @@ -1093,7 +1093,7 @@ static void dquot_decr_inodes(struct dquot *dquot, qsize_t number)
>  
>  static void dquot_decr_space(struct dquot *dquot, qsize_t number)
>  {
> -	if (sb_dqopt(dquot->dq_sb)->flags & DQUOT_NEGATIVE_USAGE ||
> +	if (dq_opt(dquot)->flags & DQUOT_NEGATIVE_USAGE ||
>  	    dquot->dq_dqb.dqb_curspace >= number)
>  		dquot->dq_dqb.dqb_curspace -= number;
>  	else
> @@ -1203,7 +1203,7 @@ static void flush_warnings(struct dquot *const *dquots, char *warntype)
>  
>  static int ignore_hardlimit(struct dquot *dquot)
>  {
> -	struct mem_dqinfo *info = &sb_dqopt(dquot->dq_sb)->info[dquot->dq_type];
> +	struct mem_dqinfo *info = &dq_opt(dquot)->info[dquot->dq_type];
>  
>  	return capable(CAP_SYS_RESOURCE) &&
>  	       (info->dqi_format->qf_fmt_id != QFMT_VFS_OLD ||
> @@ -1241,7 +1241,7 @@ static int check_idq(struct dquot *dquot, qsize_t inodes, char *warntype)
>  	    dquot->dq_dqb.dqb_itime == 0) {
>  		*warntype = QUOTA_NL_ISOFTWARN;
>  		dquot->dq_dqb.dqb_itime = get_seconds() +
> -		    sb_dqopt(dquot->dq_sb)->info[dquot->dq_type].dqi_igrace;
> +		    dq_opt(dquot)->info[dquot->dq_type].dqi_igrace;
>  	}
>  
>  	return 0;
> @@ -2331,7 +2331,7 @@ static int do_set_dqblk(struct dquot *dquot, struct fs_disk_quota *di)
>  {
>  	struct mem_dqblk *dm = &dquot->dq_dqb;
>  	int check_blim = 0, check_ilim = 0;
> -	struct mem_dqinfo *dqi = &sb_dqopt(dquot->dq_sb)->info[dquot->dq_type];
> +	struct mem_dqinfo *dqi = &dq_opt(dquot)->info[dquot->dq_type];
>  
>  	if (di->d_fieldmask & ~VFS_FS_DQ_MASK)
>  		return -EINVAL;
> diff --git a/fs/quota/quota_tree.c b/fs/quota/quota_tree.c
> index 9e48874..3eb95ec 100644
> --- a/fs/quota/quota_tree.c
> +++ b/fs/quota/quota_tree.c
> @@ -596,7 +596,7 @@ int qtree_read_dquot(struct qtree_mem_dqinfo *info, struct dquot *dquot)
>  
>  #ifdef __QUOTA_QT_PARANOIA
>  	/* Invalidated quota? */
> -	if (!sb_dqopt(dquot->dq_sb)->files[type]) {
> +	if (!dq_opt(dquot)->files[type]) {
>  		quota_error(sb, "Quota invalidated while reading!");
>  		return -EIO;
>  	}
> diff --git a/fs/quota/quota_v1.c b/fs/quota/quota_v1.c
> index 34b37a6..c7ef325 100644
> --- a/fs/quota/quota_v1.c
> +++ b/fs/quota/quota_v1.c
> @@ -57,7 +57,7 @@ static int v1_read_dqblk(struct dquot *dquot)
>  	int type = dquot->dq_type;
>  	struct v1_disk_dqblk dqblk;
>  
> -	if (!sb_dqopt(dquot->dq_sb)->files[type])
> +	if (!dq_opt(dquot)->files[type])
>  		return -EINVAL;
>  
>  	/* Set structure to 0s in case read fails/is after end of file */
> @@ -85,12 +85,12 @@ static int v1_commit_dqblk(struct dquot *dquot)
>  	v1_mem2disk_dqblk(&dqblk, &dquot->dq_dqb);
>  	if (dquot->dq_id == 0) {
>  		dqblk.dqb_btime =
> -			sb_dqopt(dquot->dq_sb)->info[type].dqi_bgrace;
> +			dq_opt(dquot)->info[type].dqi_bgrace;
>  		dqblk.dqb_itime =
> -			sb_dqopt(dquot->dq_sb)->info[type].dqi_igrace;
> +			dq_opt(dquot)->info[type].dqi_igrace;
>  	}
>  	ret = 0;
> -	if (sb_dqopt(dquot->dq_sb)->files[type])
> +	if (dq_opt(dquot)->files[type])
>  		ret = dquot->dq_sb->s_op->quota_write(dquot->dq_sb, type,
>  			(char *)&dqblk, sizeof(struct v1_disk_dqblk),
>  			v1_dqoff(dquot->dq_id));
> diff --git a/include/linux/quota.h b/include/linux/quota.h
> index 9a85412..00e1b3d 100644
> --- a/include/linux/quota.h
> +++ b/include/linux/quota.h
> @@ -182,6 +182,7 @@ enum {
>  
>  #include <asm/atomic.h>
>  
> +
>  typedef __kernel_uid32_t qid_t; /* Type in which we store ids in memory */
>  typedef long long qsize_t;	/* Type in which we store sizes */
>  
> diff --git a/include/linux/quotaops.h b/include/linux/quotaops.h
> index 9e09c9a..d81cbba 100644
> --- a/include/linux/quotaops.h
> +++ b/include/linux/quotaops.h
> @@ -17,6 +17,10 @@ static inline struct quota_info *sb_dqopt(struct super_block *sb)
>  {
>  	return &sb->s_dquot;
>  }
> +static inline struct quota_info* dq_opt(struct dquot *dq)
> +{
> +	return sb_dqopt(dq->dq_sb);
> +}
>  
>  /* i_mutex must being held */
>  static inline bool is_quota_modification(struct inode *inode, struct iattr *ia)
> -- 
> 1.6.6.1
> 
-- 
Jan Kara <jack@xxxxxxx>
SUSE Labs, CR
--
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [Samba]     [Device Mapper]     [CEPH Development]
  Powered by Linux