Ocfs2: Add a new code 'OCFS2_INFO_FREEINODE' for o2info ioctl.
PATCH 1/1 Ocfs2: Add a new code 'OCFS2_INFO_FREEINODE' for o2info ioctl.
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 <[email protected]>
--- fs/ocfs2/ioctl.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++++ fs/ocfs2/ocfs2_ioctl.h | 11 +++++ 2 files changed, 112 insertions(+), 0 deletions(-)
fs/ocfs2/ioctl.c +101 -0
@@ -23,6 +23,7 @@#include "ioctl.h" #include "resize.h" #include "refcounttree.h" +#include "sysfile.h" #include <linux/ext2_fs.h>
@@ -299,6 +300,102 @@ bail:return status; } +int ocfs2_info_scan_inode_alloc (struct inode *inode_alloc, +struct ocfs2_info_freeinode *fi, +__u32 slotnum, +int flags) +{ +int status =0 , unlock =0 ; + +struct buffer_head *bh =NULL ; +struct ocfs2_dinode *dinode_alloc =NULL ; + +mutex_lock (&inode_alloc->i_mutex); + +if (!(flags &OCFS2_INFO_FL_NON_COHERENT )) { + status =ocfs2_inode_lock (inode_alloc, &bh,0 ); +if (status <0 ) { +mlog_errno (status); + goto bail_mutex_unlock; + } + unlock =1 ; + + }else { + + status =ocfs2_read_inode_block (inode_alloc, &bh); +if (status <0 ) { +mlog_errno (status); + goto bail; + } + } + + dinode_alloc = (struct ocfs2_dinode *)bh->b_data; + + fi->ir_fi_stat[slotnum].ir_total = +le32_to_cpu (dinode_alloc->id1.bitmap1.i_total); + fi->ir_fi_stat[slotnum].ir_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 ); + +bail_mutex_unlock: +mutex_unlock (&inode_alloc->i_mutex); + +iput (inode_alloc); +brelse (bh); + +mlog_exit (status); +return status; +} + +int ocfs2_info_handle_freeinode (struct inode *inode, +struct ocfs2_info_request __user *req) +{ +u32 i; +int status = -EFAULT ; +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.ir_slotnum = osb->max_slots; + +for (i =0 ; i < oifi.ir_slotnum; i++) { + inode_alloc = +ocfs2_get_system_file_inode (osb, +INODE_ALLOC_SYSTEM_INODE , + i); +if (!inode_alloc) { +mlog (ML_ERROR ,"unable to get alloc inode in " +"slot %u\n" , i); + status = -EIO ; + goto bail; + } + + status =ocfs2_info_scan_inode_alloc (inode_alloc, &oifi, i, + oifi.ir_request.ir_flags); +if (status <0 ) + goto bail; + } + + oifi.ir_request.ir_flags |=OCFS2_INFO_FL_FILLED ; + +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) {
@@ -370,6 +467,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 ;
fs/ocfs2/ocfs2_ioctl.h +11 -0
@@ -142,6 +142,16 @@ struct ocfs2_info_journal_size {__u64 ij_journal_size; }; +struct ocfs2_info_freeinode { +struct ocfs2_info_request ir_request; +struct ocfs2_info_local_fi { +__u64 ir_total; +__u64 ir_free; + } ir_fi_stat[OCFS2_MAX_SLOTS ]; +__u32 ir_slotnum;/* out */ +__u32 ir_pad; +}; +/* Codes for ocfs2_info_request */ enum ocfs2_info_type {OCFS2_INFO_CLUSTERSIZE =1 ,
@@ -151,6 +161,7 @@ enum ocfs2_info_type {OCFS2_INFO_UUID ,OCFS2_INFO_FS_FEATURES ,OCFS2_INFO_JOURNAL_SIZE , +OCFS2_INFO_FREEINODE , OCFS2_INFO_NUM_TYPES };
Signature · 1 line
1.5.5