ocfs2-devel.oss.oracle.com archive mirror
 help / color / mirror / Atom feed
From: Mark Fasheh <mfasheh@suse.com>
To: ocfs2-devel@oss.oracle.com
Subject: [Ocfs2-devel] [PATCH 2/3] Ocfs2: Add a new code 'OCFS2_INFO_FREEINODE' for o2info ioctl.
Date: Mon, 31 Jan 2011 14:57:31 -0800	[thread overview]
Message-ID: <20110131225731.GI23899@wotan.suse.de> (raw)
In-Reply-To: <1296368761-23043-3-git-send-email-tristan.ye@oracle.com>

On Sun, Jan 30, 2011 at 02:26:00PM +0800, Tristan Ye wrote:
> The new code is dedicated to calculate free inodes number of all inode_allocs,
> then return the info to userpace in terms of an array.
> 
> Specially, flag 'OCFS2_INFO_FL_NON_COHERENT', manipulated by '--cluster-coherent'
> from userspace, is now going to be involved. setting the flag on means no cluster
> coherency considered, usually, userspace tools choose none-coherency strategy by
> default for the sake of performace.
> 
> Signed-off-by: Tristan Ye <tristan.ye@oracle.com>
> ---
>  fs/ocfs2/ioctl.c       |  122 ++++++++++++++++++++++++++++++++++++++++++++++++
>  fs/ocfs2/ocfs2_ioctl.h |   11 ++++
>  2 files changed, 133 insertions(+), 0 deletions(-)
> 
> diff --git a/fs/ocfs2/ioctl.c b/fs/ocfs2/ioctl.c
> index 731cf46..18812be 100644
> --- a/fs/ocfs2/ioctl.c
> +++ b/fs/ocfs2/ioctl.c
> @@ -23,6 +23,9 @@
>  #include "ioctl.h"
>  #include "resize.h"
>  #include "refcounttree.h"
> +#include "sysfile.h"
> +#include "dir.h"
> +#include "buffer_head_io.h"
>  
>  #include <linux/ext2_fs.h>
>  
> @@ -62,6 +65,13 @@ static inline void __o2info_clear_request_filled(struct ocfs2_info_request *req)
>  #define o2info_clear_request_filled(a) \
>  		__o2info_clear_request_filled((struct ocfs2_info_request *)&(a))
>  
> +static inline int __o2info_coherent(struct ocfs2_info_request *req)
> +{
> +	return (!(req->ir_flags & OCFS2_INFO_FL_NON_COHERENT));
> +}
> +
> +#define o2info_coherent(a) __o2info_coherent((struct ocfs2_info_request *)&(a))

Same comment about typechecking as before.


>  static int ocfs2_get_inode_attr(struct inode *inode, unsigned *flags)
>  {
>  	int status;
> @@ -321,6 +331,114 @@ bail:
>  	return status;
>  }
>  
> +int ocfs2_info_scan_inode_alloc(struct ocfs2_super *osb,
> +				struct inode *inode_alloc, u64 blkno,
> +				struct ocfs2_info_freeinode *fi, u32 slot)
> +{
> +	int status = 0, unlock = 0;
> +
> +	struct buffer_head *bh = NULL;
> +	struct ocfs2_dinode *dinode_alloc = NULL;
> +
> +	if (inode_alloc)
> +		mutex_lock(&inode_alloc->i_mutex);
> +
> +	if (o2info_coherent(*fi)) {
> +		status = ocfs2_inode_lock(inode_alloc, &bh, 0);
> +		if (status < 0) {
> +			mlog_errno(status);
> +			goto bail;
> +		}
> +		unlock = 1;
> +	} else {
> +		status = ocfs2_read_blocks_sync(osb, blkno, 1, &bh);
> +		if (status < 0) {
> +			mlog_errno(status);
> +			goto bail;
> +		}
> +	}
> +
> +	dinode_alloc = (struct ocfs2_dinode *)bh->b_data;
> +
> +	fi->ifi_stat[slot].lfi_total =
> +		le32_to_cpu(dinode_alloc->id1.bitmap1.i_total);
> +	fi->ifi_stat[slot].lfi_free =
> +		le32_to_cpu(dinode_alloc->id1.bitmap1.i_total) -
> +		le32_to_cpu(dinode_alloc->id1.bitmap1.i_used);
> +
> +bail:
> +	if (unlock)
> +		ocfs2_inode_unlock(inode_alloc, 0);
> +
> +	if (inode_alloc)
> +		mutex_unlock(&inode_alloc->i_mutex);
> +
> +	if (inode_alloc)
> +		iput(inode_alloc);
    		^^^^^^^^^^^^^^^^^^

Is this iput necessary? I don't see a balancing ref in the function.

> +
> +	brelse(bh);
> +
> +	mlog_exit(status);
> +	return status;
> +}
> +
> +int ocfs2_info_handle_freeinode(struct inode *inode,
> +				struct ocfs2_info_request __user *req)
> +{
> +	u32 i;
> +	u64 blkno = -1;
> +	char namebuf[40];
> +	int status = -EFAULT, type = INODE_ALLOC_SYSTEM_INODE;
> +	struct ocfs2_info_freeinode oifi;
> +	struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
> +	struct inode *inode_alloc = NULL;
> +
> +	if (o2info_from_user(oifi, req))
> +		goto bail;
> +
> +	oifi.ifi_slotnum = osb->max_slots;
> +
> +	for (i = 0; i < oifi.ifi_slotnum; i++) {
> +		if (o2info_coherent(oifi)) {
> +			inode_alloc = ocfs2_get_system_file_inode(osb, type, i);
> +			if (!inode_alloc) {
> +				mlog(ML_ERROR, "unable to get alloc inode in "
> +				    "slot %u\n", i);
> +				status = -EIO;
> +				goto bail;
> +			}
> +		} else {
> +			ocfs2_sprintf_system_inode_name(namebuf,
> +							sizeof(namebuf),
> +							type, i);
> +			status = ocfs2_lookup_ino_from_name(osb->sys_root_inode,
> +							    namebuf,
> +							    strlen(namebuf),
> +							    &blkno);
> +			if (status < 0) {
> +				status = -ENOENT;
> +				goto bail;
> +			}
> +		}
> +
> +		status = ocfs2_info_scan_inode_alloc(osb, inode_alloc, blkno, &oifi, i);

You need the following here:

		iput(inode_alloc);
		inode_alloc = NULL;

> +		if (status < 0)
> +			goto bail;
> +	}
> +
> +	o2info_set_request_filled(oifi);
> +
> +	if (o2info_to_user(oifi, req))
> +		goto bail;
> +
> +	status = 0;
> +bail:
> +	if (status)
> +		o2info_set_request_error(oifi, req);
> +
> +	return status;
> +}
> +
>  int ocfs2_info_handle_unknown(struct inode *inode,
>  			      struct ocfs2_info_request __user *req)
>  {
> @@ -392,6 +510,10 @@ int ocfs2_info_handle_request(struct inode *inode,
>  		if (oir.ir_size == sizeof(struct ocfs2_info_journal_size))
>  			status = ocfs2_info_handle_journal_size(inode, req);
>  		break;
> +	case OCFS2_INFO_FREEINODE:
> +		if (oir.ir_size == sizeof(struct ocfs2_info_freeinode))
> +			status = ocfs2_info_handle_freeinode(inode, req);
> +		break;
>  	default:
>  		status = ocfs2_info_handle_unknown(inode, req);
>  		break;
> diff --git a/fs/ocfs2/ocfs2_ioctl.h b/fs/ocfs2/ocfs2_ioctl.h
> index b46f39b..6b4b39a 100644
> --- a/fs/ocfs2/ocfs2_ioctl.h
> +++ b/fs/ocfs2/ocfs2_ioctl.h
> @@ -142,6 +142,16 @@ struct ocfs2_info_journal_size {
>  	__u64 ij_journal_size;
>  };
>  
> +struct ocfs2_info_freeinode {
> +	struct ocfs2_info_request ifi_req;
> +	struct ocfs2_info_local_freeinode {
> +		__u64 lfi_total;
> +		__u64 lfi_free;
> +	} ifi_stat[OCFS2_MAX_SLOTS];
> +	__u32 ifi_slotnum; /* out */
> +	__u32 ifi_pad;
> +};

Any reason why we don't keep the array (ocfs2_info_local_freeinode) at the
end of this structure like this:

struct ocfs2_info_freeinode {
	struct ocfs2_info_request ifi_req;
	__u32 ifi_slotnum; /* out */
	__u32 ifi_pad;
	struct ocfs2_info_local_freeinode {
		__u64 lfi_total;
		__u64 lfi_free;
	} ifi_stat[OCFS2_MAX_SLOTS];
};
	--Mark

--
Mark Fasheh

  reply	other threads:[~2011-01-31 22:57 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-30  6:25 [Ocfs2-devel] [PATCH 0/3] Ocfs2: Adding new codes 'OCFS2_INFO_FREEINODE' and 'OCFS2_INFO_FREEFRAG' for o2info ioctl V2 Tristan Ye
2011-01-30  6:25 ` [Ocfs2-devel] [PATCH 1/3] Ocfs2: Using macro to set/clear *FILLED* flags in info handler Tristan Ye
2011-01-31 22:15   ` Mark Fasheh
2011-02-01  1:10     ` Joel Becker
2011-02-01  3:06       ` Mark Fasheh
2011-02-01  6:01         ` Joel Becker
2011-02-01  7:53           ` Tristan Ye
2011-02-01 17:37           ` Mark Fasheh
2011-02-01  7:48     ` Tristan Ye
2011-02-20 12:08   ` Joel Becker
2011-01-30  6:26 ` [Ocfs2-devel] [PATCH 2/3] Ocfs2: Add a new code 'OCFS2_INFO_FREEINODE' for o2info ioctl Tristan Ye
2011-01-31 22:57   ` Mark Fasheh [this message]
2011-02-01  7:52     ` Tristan Ye
2011-02-20 12:07   ` Joel Becker
2011-02-20 12:59     ` Tristan Ye
2011-02-21  2:04       ` Joel Becker
2011-02-21 18:17       ` Sunil Mushran
2011-01-30  6:26 ` [Ocfs2-devel] [PATCH 3/3] Ocfs2: Add a new code 'OCFS2_INFO_FREEFRAG' " Tristan Ye
  -- strict thread matches above, loose matches on Subject: below --
2011-05-24 10:07 [Ocfs2-devel] [PATCH 0/3] Ocfs2: Complete rest of o2info patches(v5) Tristan Ye
2011-05-24 10:07 ` [Ocfs2-devel] [PATCH 2/3] Ocfs2: Add a new code 'OCFS2_INFO_FREEINODE' for o2info ioctl Tristan Ye
2011-03-29  2:11 [Ocfs2-devel] [PATCH 0/3] Ocfs2: Complete rest of o2info patches Tristan Ye
2011-03-29  2:11 ` [Ocfs2-devel] [PATCH 2/3] Ocfs2: Add a new code 'OCFS2_INFO_FREEINODE' for o2info ioctl Tristan Ye
2011-02-22  4:59 Tristan Ye
2011-02-22  6:09 ` Joel Becker
2011-02-22  8:02   ` Tristan Ye
2011-02-22  8:15     ` Joel Becker
2011-02-22  8:26       ` Tristan Ye
2011-02-18  4:26 [Ocfs2-devel] [PATCH 0/3] Ocfs2: Adding new codes 'OCFS2_INFO_FREEINODE' and 'OCFS2_INFO_FREEFRAG' for o2info ioctl V3 Tristan Ye
2011-02-18  4:26 ` [Ocfs2-devel] [PATCH 2/3] Ocfs2: Add a new code 'OCFS2_INFO_FREEINODE' for o2info ioctl Tristan Ye
2010-11-16 10:13 [Ocfs2-devel] [PATCH 0/3] Ocfs2: Adding new codes 'OCFS2_INFO_FREEINODE' and 'OCFS2_INFO_FREEFRAG' for o2info ioctl V2 Tristan Ye
2010-11-16 10:13 ` [Ocfs2-devel] [PATCH 2/3] Ocfs2: Add a new code 'OCFS2_INFO_FREEINODE' for o2info ioctl Tristan Ye
2010-12-07  1:07   ` Joel Becker
2010-12-07  1:46     ` Tristan Ye

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=20110131225731.GI23899@wotan.suse.de \
    --to=mfasheh@suse.com \
    --cc=ocfs2-devel@oss.oracle.com \
    /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).