Commit 9e33d69f authored by Jan Kara's avatar Jan Kara Committed by Mark Fasheh

ocfs2: Implementation of local and global quota file handling

For each quota type each node has local quota file. In this file it stores
changes users have made to disk usage via this node. Once in a while this
information is synced to global file (and thus with other nodes) so that
limits enforcement at least aproximately works.

Global quota files contain all the information about usage and limits. It's
mostly handled by the generic VFS code (which implements a trie of structures
inside a quota file). We only have to provide functions to convert structures
from on-disk format to in-memory one. We also have to provide wrappers for
various quota functions starting transactions and acquiring necessary cluster
locks before the actual IO is really started.
Signed-off-by: default avatarJan Kara <jack@suse.cz>
Signed-off-by: default avatarMark Fasheh <mfasheh@suse.com>
parent bbbd0eb3
...@@ -35,6 +35,8 @@ ocfs2-objs := \ ...@@ -35,6 +35,8 @@ ocfs2-objs := \
sysfile.o \ sysfile.o \
uptodate.o \ uptodate.o \
ver.o \ ver.o \
quota_local.o \
quota_global.o \
xattr.o xattr.o
ifeq ($(CONFIG_OCFS2_FS_POSIX_ACL),y) ifeq ($(CONFIG_OCFS2_FS_POSIX_ACL),y)
......
...@@ -113,6 +113,7 @@ ...@@ -113,6 +113,7 @@
#define ML_QUORUM 0x0000000008000000ULL /* net connection quorum */ #define ML_QUORUM 0x0000000008000000ULL /* net connection quorum */
#define ML_EXPORT 0x0000000010000000ULL /* ocfs2 export operations */ #define ML_EXPORT 0x0000000010000000ULL /* ocfs2 export operations */
#define ML_XATTR 0x0000000020000000ULL /* ocfs2 extended attributes */ #define ML_XATTR 0x0000000020000000ULL /* ocfs2 extended attributes */
#define ML_QUOTA 0x0000000040000000ULL /* ocfs2 quota operations */
/* bits that are infrequently given and frequently matched in the high word */ /* bits that are infrequently given and frequently matched in the high word */
#define ML_ERROR 0x0000000100000000ULL /* sent to KERN_ERR */ #define ML_ERROR 0x0000000100000000ULL /* sent to KERN_ERR */
#define ML_NOTICE 0x0000000200000000ULL /* setn to KERN_NOTICE */ #define ML_NOTICE 0x0000000200000000ULL /* setn to KERN_NOTICE */
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include <linux/debugfs.h> #include <linux/debugfs.h>
#include <linux/seq_file.h> #include <linux/seq_file.h>
#include <linux/time.h> #include <linux/time.h>
#include <linux/quotaops.h>
#define MLOG_MASK_PREFIX ML_DLM_GLUE #define MLOG_MASK_PREFIX ML_DLM_GLUE
#include <cluster/masklog.h> #include <cluster/masklog.h>
...@@ -51,6 +52,7 @@ ...@@ -51,6 +52,7 @@
#include "slot_map.h" #include "slot_map.h"
#include "super.h" #include "super.h"
#include "uptodate.h" #include "uptodate.h"
#include "quota.h"
#include "buffer_head_io.h" #include "buffer_head_io.h"
...@@ -68,6 +70,7 @@ struct ocfs2_mask_waiter { ...@@ -68,6 +70,7 @@ struct ocfs2_mask_waiter {
static struct ocfs2_super *ocfs2_get_dentry_osb(struct ocfs2_lock_res *lockres); static struct ocfs2_super *ocfs2_get_dentry_osb(struct ocfs2_lock_res *lockres);
static struct ocfs2_super *ocfs2_get_inode_osb(struct ocfs2_lock_res *lockres); static struct ocfs2_super *ocfs2_get_inode_osb(struct ocfs2_lock_res *lockres);
static struct ocfs2_super *ocfs2_get_file_osb(struct ocfs2_lock_res *lockres); static struct ocfs2_super *ocfs2_get_file_osb(struct ocfs2_lock_res *lockres);
static struct ocfs2_super *ocfs2_get_qinfo_osb(struct ocfs2_lock_res *lockres);
/* /*
* Return value from ->downconvert_worker functions. * Return value from ->downconvert_worker functions.
...@@ -102,6 +105,7 @@ static int ocfs2_dentry_convert_worker(struct ocfs2_lock_res *lockres, ...@@ -102,6 +105,7 @@ static int ocfs2_dentry_convert_worker(struct ocfs2_lock_res *lockres,
static void ocfs2_dentry_post_unlock(struct ocfs2_super *osb, static void ocfs2_dentry_post_unlock(struct ocfs2_super *osb,
struct ocfs2_lock_res *lockres); struct ocfs2_lock_res *lockres);
static void ocfs2_set_qinfo_lvb(struct ocfs2_lock_res *lockres);
#define mlog_meta_lvb(__level, __lockres) ocfs2_dump_meta_lvb_info(__level, __PRETTY_FUNCTION__, __LINE__, __lockres) #define mlog_meta_lvb(__level, __lockres) ocfs2_dump_meta_lvb_info(__level, __PRETTY_FUNCTION__, __LINE__, __lockres)
...@@ -258,6 +262,12 @@ static struct ocfs2_lock_res_ops ocfs2_flock_lops = { ...@@ -258,6 +262,12 @@ static struct ocfs2_lock_res_ops ocfs2_flock_lops = {
.flags = 0, .flags = 0,
}; };
static struct ocfs2_lock_res_ops ocfs2_qinfo_lops = {
.set_lvb = ocfs2_set_qinfo_lvb,
.get_osb = ocfs2_get_qinfo_osb,
.flags = LOCK_TYPE_REQUIRES_REFRESH | LOCK_TYPE_USES_LVB,
};
static inline int ocfs2_is_inode_lock(struct ocfs2_lock_res *lockres) static inline int ocfs2_is_inode_lock(struct ocfs2_lock_res *lockres)
{ {
return lockres->l_type == OCFS2_LOCK_TYPE_META || return lockres->l_type == OCFS2_LOCK_TYPE_META ||
...@@ -279,6 +289,13 @@ static inline struct ocfs2_dentry_lock *ocfs2_lock_res_dl(struct ocfs2_lock_res ...@@ -279,6 +289,13 @@ static inline struct ocfs2_dentry_lock *ocfs2_lock_res_dl(struct ocfs2_lock_res
return (struct ocfs2_dentry_lock *)lockres->l_priv; return (struct ocfs2_dentry_lock *)lockres->l_priv;
} }
static inline struct ocfs2_mem_dqinfo *ocfs2_lock_res_qinfo(struct ocfs2_lock_res *lockres)
{
BUG_ON(lockres->l_type != OCFS2_LOCK_TYPE_QINFO);
return (struct ocfs2_mem_dqinfo *)lockres->l_priv;
}
static inline struct ocfs2_super *ocfs2_get_lockres_osb(struct ocfs2_lock_res *lockres) static inline struct ocfs2_super *ocfs2_get_lockres_osb(struct ocfs2_lock_res *lockres)
{ {
if (lockres->l_ops->get_osb) if (lockres->l_ops->get_osb)
...@@ -507,6 +524,13 @@ static struct ocfs2_super *ocfs2_get_inode_osb(struct ocfs2_lock_res *lockres) ...@@ -507,6 +524,13 @@ static struct ocfs2_super *ocfs2_get_inode_osb(struct ocfs2_lock_res *lockres)
return OCFS2_SB(inode->i_sb); return OCFS2_SB(inode->i_sb);
} }
static struct ocfs2_super *ocfs2_get_qinfo_osb(struct ocfs2_lock_res *lockres)
{
struct ocfs2_mem_dqinfo *info = lockres->l_priv;
return OCFS2_SB(info->dqi_gi.dqi_sb);
}
static struct ocfs2_super *ocfs2_get_file_osb(struct ocfs2_lock_res *lockres) static struct ocfs2_super *ocfs2_get_file_osb(struct ocfs2_lock_res *lockres)
{ {
struct ocfs2_file_private *fp = lockres->l_priv; struct ocfs2_file_private *fp = lockres->l_priv;
...@@ -609,6 +633,17 @@ void ocfs2_file_lock_res_init(struct ocfs2_lock_res *lockres, ...@@ -609,6 +633,17 @@ void ocfs2_file_lock_res_init(struct ocfs2_lock_res *lockres,
lockres->l_flags |= OCFS2_LOCK_NOCACHE; lockres->l_flags |= OCFS2_LOCK_NOCACHE;
} }
void ocfs2_qinfo_lock_res_init(struct ocfs2_lock_res *lockres,
struct ocfs2_mem_dqinfo *info)
{
ocfs2_lock_res_init_once(lockres);
ocfs2_build_lock_name(OCFS2_LOCK_TYPE_QINFO, info->dqi_gi.dqi_type,
0, lockres->l_name);
ocfs2_lock_res_init_common(OCFS2_SB(info->dqi_gi.dqi_sb), lockres,
OCFS2_LOCK_TYPE_QINFO, &ocfs2_qinfo_lops,
info);
}
void ocfs2_lock_res_free(struct ocfs2_lock_res *res) void ocfs2_lock_res_free(struct ocfs2_lock_res *res)
{ {
mlog_entry_void(); mlog_entry_void();
...@@ -3445,6 +3480,117 @@ static int ocfs2_dentry_convert_worker(struct ocfs2_lock_res *lockres, ...@@ -3445,6 +3480,117 @@ static int ocfs2_dentry_convert_worker(struct ocfs2_lock_res *lockres,
return UNBLOCK_CONTINUE_POST; return UNBLOCK_CONTINUE_POST;
} }
static void ocfs2_set_qinfo_lvb(struct ocfs2_lock_res *lockres)
{
struct ocfs2_qinfo_lvb *lvb;
struct ocfs2_mem_dqinfo *oinfo = ocfs2_lock_res_qinfo(lockres);
struct mem_dqinfo *info = sb_dqinfo(oinfo->dqi_gi.dqi_sb,
oinfo->dqi_gi.dqi_type);
mlog_entry_void();
lvb = (struct ocfs2_qinfo_lvb *)ocfs2_dlm_lvb(&lockres->l_lksb);
lvb->lvb_version = OCFS2_QINFO_LVB_VERSION;
lvb->lvb_bgrace = cpu_to_be32(info->dqi_bgrace);
lvb->lvb_igrace = cpu_to_be32(info->dqi_igrace);
lvb->lvb_syncms = cpu_to_be32(oinfo->dqi_syncms);
lvb->lvb_blocks = cpu_to_be32(oinfo->dqi_gi.dqi_blocks);
lvb->lvb_free_blk = cpu_to_be32(oinfo->dqi_gi.dqi_free_blk);
lvb->lvb_free_entry = cpu_to_be32(oinfo->dqi_gi.dqi_free_entry);
mlog_exit_void();
}
void ocfs2_qinfo_unlock(struct ocfs2_mem_dqinfo *oinfo, int ex)
{
struct ocfs2_lock_res *lockres = &oinfo->dqi_gqlock;
struct ocfs2_super *osb = OCFS2_SB(oinfo->dqi_gi.dqi_sb);
int level = ex ? DLM_LOCK_EX : DLM_LOCK_PR;
mlog_entry_void();
if (!ocfs2_is_hard_readonly(osb) && !ocfs2_mount_local(osb))
ocfs2_cluster_unlock(osb, lockres, level);
mlog_exit_void();
}
static int ocfs2_refresh_qinfo(struct ocfs2_mem_dqinfo *oinfo)
{
struct mem_dqinfo *info = sb_dqinfo(oinfo->dqi_gi.dqi_sb,
oinfo->dqi_gi.dqi_type);
struct ocfs2_lock_res *lockres = &oinfo->dqi_gqlock;
struct ocfs2_qinfo_lvb *lvb = ocfs2_dlm_lvb(&lockres->l_lksb);
struct buffer_head *bh;
struct ocfs2_global_disk_dqinfo *gdinfo;
int status = 0;
if (lvb->lvb_version == OCFS2_QINFO_LVB_VERSION) {
info->dqi_bgrace = be32_to_cpu(lvb->lvb_bgrace);
info->dqi_igrace = be32_to_cpu(lvb->lvb_igrace);
oinfo->dqi_syncms = be32_to_cpu(lvb->lvb_syncms);
oinfo->dqi_gi.dqi_blocks = be32_to_cpu(lvb->lvb_blocks);
oinfo->dqi_gi.dqi_free_blk = be32_to_cpu(lvb->lvb_free_blk);
oinfo->dqi_gi.dqi_free_entry =
be32_to_cpu(lvb->lvb_free_entry);
} else {
bh = ocfs2_read_quota_block(oinfo->dqi_gqinode, 0, &status);
if (!bh) {
mlog_errno(status);
goto bail;
}
gdinfo = (struct ocfs2_global_disk_dqinfo *)
(bh->b_data + OCFS2_GLOBAL_INFO_OFF);
info->dqi_bgrace = le32_to_cpu(gdinfo->dqi_bgrace);
info->dqi_igrace = le32_to_cpu(gdinfo->dqi_igrace);
oinfo->dqi_syncms = le32_to_cpu(gdinfo->dqi_syncms);
oinfo->dqi_gi.dqi_blocks = le32_to_cpu(gdinfo->dqi_blocks);
oinfo->dqi_gi.dqi_free_blk = le32_to_cpu(gdinfo->dqi_free_blk);
oinfo->dqi_gi.dqi_free_entry =
le32_to_cpu(gdinfo->dqi_free_entry);
brelse(bh);
ocfs2_track_lock_refresh(lockres);
}
bail:
return status;
}
/* Lock quota info, this function expects at least shared lock on the quota file
* so that we can safely refresh quota info from disk. */
int ocfs2_qinfo_lock(struct ocfs2_mem_dqinfo *oinfo, int ex)
{
struct ocfs2_lock_res *lockres = &oinfo->dqi_gqlock;
struct ocfs2_super *osb = OCFS2_SB(oinfo->dqi_gi.dqi_sb);
int level = ex ? DLM_LOCK_EX : DLM_LOCK_PR;
int status = 0;
mlog_entry_void();
/* On RO devices, locking really isn't needed... */
if (ocfs2_is_hard_readonly(osb)) {
if (ex)
status = -EROFS;
goto bail;
}
if (ocfs2_mount_local(osb))
goto bail;
status = ocfs2_cluster_lock(osb, lockres, level, 0, 0);
if (status < 0) {
mlog_errno(status);
goto bail;
}
if (!ocfs2_should_refresh_lock_res(lockres))
goto bail;
/* OK, we have the lock but we need to refresh the quota info */
status = ocfs2_refresh_qinfo(oinfo);
if (status)
ocfs2_qinfo_unlock(oinfo, ex);
ocfs2_complete_lock_res_refresh(lockres, status);
bail:
mlog_exit(status);
return status;
}
/* /*
* This is the filesystem locking protocol. It provides the lock handling * This is the filesystem locking protocol. It provides the lock handling
* hooks for the underlying DLM. It has a maximum version number. * hooks for the underlying DLM. It has a maximum version number.
......
...@@ -49,6 +49,19 @@ struct ocfs2_meta_lvb { ...@@ -49,6 +49,19 @@ struct ocfs2_meta_lvb {
__be32 lvb_reserved2; __be32 lvb_reserved2;
}; };
#define OCFS2_QINFO_LVB_VERSION 1
struct ocfs2_qinfo_lvb {
__u8 lvb_version;
__u8 lvb_reserved[3];
__be32 lvb_bgrace;
__be32 lvb_igrace;
__be32 lvb_syncms;
__be32 lvb_blocks;
__be32 lvb_free_blk;
__be32 lvb_free_entry;
};
/* ocfs2_inode_lock_full() 'arg_flags' flags */ /* ocfs2_inode_lock_full() 'arg_flags' flags */
/* don't wait on recovery. */ /* don't wait on recovery. */
#define OCFS2_META_LOCK_RECOVERY (0x01) #define OCFS2_META_LOCK_RECOVERY (0x01)
...@@ -69,6 +82,9 @@ void ocfs2_dentry_lock_res_init(struct ocfs2_dentry_lock *dl, ...@@ -69,6 +82,9 @@ void ocfs2_dentry_lock_res_init(struct ocfs2_dentry_lock *dl,
struct ocfs2_file_private; struct ocfs2_file_private;
void ocfs2_file_lock_res_init(struct ocfs2_lock_res *lockres, void ocfs2_file_lock_res_init(struct ocfs2_lock_res *lockres,
struct ocfs2_file_private *fp); struct ocfs2_file_private *fp);
struct ocfs2_mem_dqinfo;
void ocfs2_qinfo_lock_res_init(struct ocfs2_lock_res *lockres,
struct ocfs2_mem_dqinfo *info);
void ocfs2_lock_res_free(struct ocfs2_lock_res *res); void ocfs2_lock_res_free(struct ocfs2_lock_res *res);
int ocfs2_create_new_inode_locks(struct inode *inode); int ocfs2_create_new_inode_locks(struct inode *inode);
int ocfs2_drop_inode_locks(struct inode *inode); int ocfs2_drop_inode_locks(struct inode *inode);
...@@ -103,6 +119,9 @@ int ocfs2_dentry_lock(struct dentry *dentry, int ex); ...@@ -103,6 +119,9 @@ int ocfs2_dentry_lock(struct dentry *dentry, int ex);
void ocfs2_dentry_unlock(struct dentry *dentry, int ex); void ocfs2_dentry_unlock(struct dentry *dentry, int ex);
int ocfs2_file_lock(struct file *file, int ex, int trylock); int ocfs2_file_lock(struct file *file, int ex, int trylock);
void ocfs2_file_unlock(struct file *file); void ocfs2_file_unlock(struct file *file);
int ocfs2_qinfo_lock(struct ocfs2_mem_dqinfo *oinfo, int ex);
void ocfs2_qinfo_unlock(struct ocfs2_mem_dqinfo *oinfo, int ex);
void ocfs2_mark_lockres_freeing(struct ocfs2_lock_res *lockres); void ocfs2_mark_lockres_freeing(struct ocfs2_lock_res *lockres);
void ocfs2_simple_drop_lockres(struct ocfs2_super *osb, void ocfs2_simple_drop_lockres(struct ocfs2_super *osb,
......
...@@ -304,7 +304,7 @@ static int ocfs2_set_inode_size(handle_t *handle, ...@@ -304,7 +304,7 @@ static int ocfs2_set_inode_size(handle_t *handle,
return status; return status;
} }
static int ocfs2_simple_size_update(struct inode *inode, int ocfs2_simple_size_update(struct inode *inode,
struct buffer_head *di_bh, struct buffer_head *di_bh,
u64 new_i_size) u64 new_i_size)
{ {
......
...@@ -51,6 +51,9 @@ int ocfs2_add_inode_data(struct ocfs2_super *osb, ...@@ -51,6 +51,9 @@ int ocfs2_add_inode_data(struct ocfs2_super *osb,
struct ocfs2_alloc_context *data_ac, struct ocfs2_alloc_context *data_ac,
struct ocfs2_alloc_context *meta_ac, struct ocfs2_alloc_context *meta_ac,
enum ocfs2_alloc_restarted *reason_ret); enum ocfs2_alloc_restarted *reason_ret);
int ocfs2_simple_size_update(struct inode *inode,
struct buffer_head *di_bh,
u64 new_i_size);
int ocfs2_extend_no_holes(struct inode *inode, u64 new_i_size, int ocfs2_extend_no_holes(struct inode *inode, u64 new_i_size,
u64 zero_to); u64 zero_to);
int ocfs2_setattr(struct dentry *dentry, struct iattr *attr); int ocfs2_setattr(struct dentry *dentry, struct iattr *attr);
......
...@@ -142,6 +142,8 @@ int ocfs2_mark_inode_dirty(handle_t *handle, ...@@ -142,6 +142,8 @@ int ocfs2_mark_inode_dirty(handle_t *handle,
struct buffer_head *bh); struct buffer_head *bh);
int ocfs2_aio_read(struct file *file, struct kiocb *req, struct iocb *iocb); int ocfs2_aio_read(struct file *file, struct kiocb *req, struct iocb *iocb);
int ocfs2_aio_write(struct file *file, struct kiocb *req, struct iocb *iocb); int ocfs2_aio_write(struct file *file, struct kiocb *req, struct iocb *iocb);
struct buffer_head *ocfs2_bread(struct inode *inode,
int block, int *err, int reada);
void ocfs2_set_inode_flags(struct inode *inode); void ocfs2_set_inode_flags(struct inode *inode);
void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi); void ocfs2_get_inode_flags(struct ocfs2_inode_info *oi);
......
...@@ -883,6 +883,109 @@ static inline int ocfs2_xattr_get_type(struct ocfs2_xattr_entry *xe) ...@@ -883,6 +883,109 @@ static inline int ocfs2_xattr_get_type(struct ocfs2_xattr_entry *xe)
return xe->xe_type & OCFS2_XATTR_TYPE_MASK; return xe->xe_type & OCFS2_XATTR_TYPE_MASK;
} }
/*
* On disk structures for global quota file
*/
/* Magic numbers and known versions for global quota files */
#define OCFS2_GLOBAL_QMAGICS {\
0x0cf52470, /* USRQUOTA */ \
0x0cf52471 /* GRPQUOTA */ \
}
#define OCFS2_GLOBAL_QVERSIONS {\
0, \
0, \
}
/* Each block of each quota file has a certain fixed number of bytes reserved
* for OCFS2 internal use at its end. OCFS2 can use it for things like
* checksums, etc. */
#define OCFS2_QBLK_RESERVED_SPACE 8
/* Generic header of all quota files */
struct ocfs2_disk_dqheader {
__le32 dqh_magic; /* Magic number identifying file */
__le32 dqh_version; /* Quota format version */
};
#define OCFS2_GLOBAL_INFO_OFF (sizeof(struct ocfs2_disk_dqheader))
/* Information header of global quota file (immediately follows the generic
* header) */
struct ocfs2_global_disk_dqinfo {
/*00*/ __le32 dqi_bgrace; /* Grace time for space softlimit excess */
__le32 dqi_igrace; /* Grace time for inode softlimit excess */
__le32 dqi_syncms; /* Time after which we sync local changes to
* global quota file */
__le32 dqi_blocks; /* Number of blocks in quota file */
/*10*/ __le32 dqi_free_blk; /* First free block in quota file */
__le32 dqi_free_entry; /* First block with free dquot entry in quota
* file */
};
/* Structure with global user / group information. We reserve some space
* for future use. */
struct ocfs2_global_disk_dqblk {
/*00*/ __le32 dqb_id; /* ID the structure belongs to */
__le32 dqb_use_count; /* Number of nodes having reference to this structure */
__le64 dqb_ihardlimit; /* absolute limit on allocated inodes */
/*10*/ __le64 dqb_isoftlimit; /* preferred inode limit */
__le64 dqb_curinodes; /* current # allocated inodes */
/*20*/ __le64 dqb_bhardlimit; /* absolute limit on disk space */
__le64 dqb_bsoftlimit; /* preferred limit on disk space */
/*30*/ __le64 dqb_curspace; /* current space occupied */
__le64 dqb_btime; /* time limit for excessive disk use */
/*40*/ __le64 dqb_itime; /* time limit for excessive inode use */
__le64 dqb_pad1;
/*50*/ __le64 dqb_pad2;
};
/*
* On-disk structures for local quota file
*/
/* Magic numbers and known versions for local quota files */
#define OCFS2_LOCAL_QMAGICS {\
0x0cf524c0, /* USRQUOTA */ \
0x0cf524c1 /* GRPQUOTA */ \
}
#define OCFS2_LOCAL_QVERSIONS {\
0, \
0, \
}
/* Quota flags in dqinfo header */
#define OLQF_CLEAN 0x0001 /* Quota file is empty (this should be after\
* quota has been cleanly turned off) */
#define OCFS2_LOCAL_INFO_OFF (sizeof(struct ocfs2_disk_dqheader))
/* Information header of local quota file (immediately follows the generic
* header) */
struct ocfs2_local_disk_dqinfo {
__le32 dqi_flags; /* Flags for quota file */
__le32 dqi_chunks; /* Number of chunks of quota structures
* with a bitmap */
__le32 dqi_blocks; /* Number of blocks allocated for quota file */
};
/* Header of one chunk of a quota file */
struct ocfs2_local_disk_chunk {
__le32 dqc_free; /* Number of free entries in the bitmap */
u8 dqc_bitmap[0]; /* Bitmap of entries in the corresponding
* chunk of quota file */
};
/* One entry in local quota file */
struct ocfs2_local_disk_dqblk {
/*00*/ __le64 dqb_id; /* id this quota applies to */
__le64 dqb_spacemod; /* Change in the amount of used space */
/*10*/ __le64 dqb_inodemod; /* Change in the amount of used inodes */
};
#ifdef __KERNEL__ #ifdef __KERNEL__
static inline int ocfs2_fast_symlink_chars(struct super_block *sb) static inline int ocfs2_fast_symlink_chars(struct super_block *sb)
{ {
......
...@@ -46,6 +46,7 @@ enum ocfs2_lock_type { ...@@ -46,6 +46,7 @@ enum ocfs2_lock_type {
OCFS2_LOCK_TYPE_DENTRY, OCFS2_LOCK_TYPE_DENTRY,
OCFS2_LOCK_TYPE_OPEN, OCFS2_LOCK_TYPE_OPEN,
OCFS2_LOCK_TYPE_FLOCK, OCFS2_LOCK_TYPE_FLOCK,
OCFS2_LOCK_TYPE_QINFO,
OCFS2_NUM_LOCK_TYPES OCFS2_NUM_LOCK_TYPES
}; };
...@@ -77,6 +78,9 @@ static inline char ocfs2_lock_type_char(enum ocfs2_lock_type type) ...@@ -77,6 +78,9 @@ static inline char ocfs2_lock_type_char(enum ocfs2_lock_type type)
case OCFS2_LOCK_TYPE_FLOCK: case OCFS2_LOCK_TYPE_FLOCK:
c = 'F'; c = 'F';
break; break;
case OCFS2_LOCK_TYPE_QINFO:
c = 'Q';
break;
default: default:
c = '\0'; c = '\0';
} }
...@@ -95,6 +99,7 @@ static char *ocfs2_lock_type_strings[] = { ...@@ -95,6 +99,7 @@ static char *ocfs2_lock_type_strings[] = {
[OCFS2_LOCK_TYPE_DENTRY] = "Dentry", [OCFS2_LOCK_TYPE_DENTRY] = "Dentry",
[OCFS2_LOCK_TYPE_OPEN] = "Open", [OCFS2_LOCK_TYPE_OPEN] = "Open",
[OCFS2_LOCK_TYPE_FLOCK] = "Flock", [OCFS2_LOCK_TYPE_FLOCK] = "Flock",
[OCFS2_LOCK_TYPE_QINFO] = "Quota",
}; };
static inline const char *ocfs2_lock_type_string(enum ocfs2_lock_type type) static inline const char *ocfs2_lock_type_string(enum ocfs2_lock_type type)
......
/*
* quota.h for OCFS2
*
* On disk quota structures for local and global quota file, in-memory
* structures.
*
*/
#ifndef _OCFS2_QUOTA_H
#define _OCFS2_QUOTA_H
#include <linux/types.h>
#include <linux/slab.h>
#include <linux/quota.h>
#include <linux/list.h>
#include <linux/dqblk_qtree.h>
#include "ocfs2.h"
/* Common stuff */
/* id number of quota format */
#define QFMT_OCFS2 3
/*
* In-memory structures
*/
struct ocfs2_dquot {
struct dquot dq_dquot; /* Generic VFS dquot */
loff_t dq_local_off; /* Offset in the local quota file */
struct ocfs2_quota_chunk *dq_chunk; /* Chunk dquot is in */
unsigned int dq_use_count; /* Number of nodes having reference to this entry in global quota file */
s64 dq_origspace; /* Last globally synced space usage */
s64 dq_originodes; /* Last globally synced inode usage */
};
/* In-memory structure with quota header information */
struct ocfs2_mem_dqinfo {
unsigned int dqi_type; /* Quota type this structure describes */
unsigned int dqi_chunks; /* Number of chunks in local quota file */
unsigned int dqi_blocks; /* Number of blocks allocated for local quota file */
unsigned int dqi_syncms; /* How often should we sync with other nodes */
struct list_head dqi_chunk; /* List of chunks */
struct inode *dqi_gqinode; /* Global quota file inode */
struct ocfs2_lock_res dqi_gqlock; /* Lock protecting quota information structure */
struct buffer_head *dqi_gqi_bh; /* Buffer head with global quota file inode - set only if inode lock is obtained */
int dqi_gqi_count; /* Number of holders of dqi_gqi_bh */
struct buffer_head *dqi_lqi_bh; /* Buffer head with local quota file inode */
struct buffer_head *dqi_ibh; /* Buffer with information header */
struct qtree_mem_dqinfo dqi_gi; /* Info about global file */
};
static inline struct ocfs2_dquot *OCFS2_DQUOT(struct dquot *dquot)
{
return container_of(dquot, struct ocfs2_dquot, dq_dquot);
}
struct ocfs2_quota_chunk {
struct list_head qc_chunk; /* List of quotafile chunks */
int qc_num; /* Number of quota chunk */
struct buffer_head *qc_headerbh; /* Buffer head with chunk header */
};
extern struct kmem_cache *ocfs2_dquot_cachep;
extern struct kmem_cache *ocfs2_qf_chunk_cachep;
extern struct qtree_fmt_operations ocfs2_global_ops;
ssize_t ocfs2_quota_read(struct super_block *sb, int type, char *data,
size_t len, loff_t off);
ssize_t ocfs2_quota_write(struct super_block *sb, int type,
const char *data, size_t len, loff_t off);
int ocfs2_global_read_info(struct super_block *sb, int type);
int ocfs2_global_write_info(struct super_block *sb, int type);
int ocfs2_global_read_dquot(struct dquot *dquot);
int __ocfs2_sync_dquot(struct dquot *dquot, int freeing);
static inline int ocfs2_sync_dquot(struct dquot *dquot)
{
return __ocfs2_sync_dquot(dquot, 0);
}
static inline int ocfs2_global_release_dquot(struct dquot *dquot)
{
return __ocfs2_sync_dquot(dquot, 1);
}
int ocfs2_lock_global_qf(struct ocfs2_mem_dqinfo *oinfo, int ex);
void ocfs2_unlock_global_qf(struct ocfs2_mem_dqinfo *oinfo, int ex);
struct buffer_head *ocfs2_read_quota_block(struct inode *inode,
int block, int *err);
extern struct dquot_operations ocfs2_quota_operations;
extern struct quota_format_type ocfs2_quota_format;
#endif /* _OCFS2_QUOTA_H */
This diff is collapsed.
This diff is collapsed.
...@@ -65,10 +65,13 @@ ...@@ -65,10 +65,13 @@
#include "uptodate.h" #include "uptodate.h"
#include "ver.h" #include "ver.h"
#include "xattr.h" #include "xattr.h"
#include "quota.h"
#include "buffer_head_io.h" #include "buffer_head_io.h"
static struct kmem_cache *ocfs2_inode_cachep = NULL; static struct kmem_cache *ocfs2_inode_cachep = NULL;
struct kmem_cache *ocfs2_dquot_cachep;
struct kmem_cache *ocfs2_qf_chunk_cachep;
/* OCFS2 needs to schedule several differnt types of work which /* OCFS2 needs to schedule several differnt types of work which
* require cluster locking, disk I/O, recovery waits, etc. Since these * require cluster locking, disk I/O, recovery waits, etc. Since these
...@@ -137,6 +140,8 @@ static const struct super_operations ocfs2_sops = { ...@@ -137,6 +140,8 @@ static const struct super_operations ocfs2_sops = {
.put_super = ocfs2_put_super, .put_super = ocfs2_put_super,
.remount_fs = ocfs2_remount, .remount_fs = ocfs2_remount,
.show_options = ocfs2_show_options, .show_options = ocfs2_show_options,
.quota_read = ocfs2_quota_read,
.quota_write = ocfs2_quota_write,
}; };
enum { enum {
...@@ -1104,6 +1109,7 @@ static int __init ocfs2_init(void) ...@@ -1104,6 +1109,7 @@ static int __init ocfs2_init(void)
ocfs2_set_locking_protocol(); ocfs2_set_locking_protocol();
status = register_quota_format(&ocfs2_quota_format);
leave: leave:
if (status < 0) { if (status < 0) {
ocfs2_free_mem_caches(); ocfs2_free_mem_caches();
...@@ -1127,6 +1133,8 @@ static void __exit ocfs2_exit(void) ...@@ -1127,6 +1133,8 @@ static void __exit ocfs2_exit(void)
destroy_workqueue(ocfs2_wq); destroy_workqueue(ocfs2_wq);
} }
unregister_quota_format(&ocfs2_quota_format);
debugfs_remove(ocfs2_debugfs_root); debugfs_remove(ocfs2_debugfs_root);
ocfs2_free_mem_caches(); ocfs2_free_mem_caches();
...@@ -1242,8 +1250,27 @@ static int ocfs2_initialize_mem_caches(void) ...@@ -1242,8 +1250,27 @@ static int ocfs2_initialize_mem_caches(void)
(SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT| (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
SLAB_MEM_SPREAD), SLAB_MEM_SPREAD),
ocfs2_inode_init_once); ocfs2_inode_init_once);
if (!ocfs2_inode_cachep) ocfs2_dquot_cachep = kmem_cache_create("ocfs2_dquot_cache",
sizeof(struct ocfs2_dquot),
0,
(SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
SLAB_MEM_SPREAD),
NULL);
ocfs2_qf_chunk_cachep = kmem_cache_create("ocfs2_qf_chunk_cache",
sizeof(struct ocfs2_quota_chunk),
0,
(SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD),
NULL);
if (!ocfs2_inode_cachep || !ocfs2_dquot_cachep ||
!ocfs2_qf_chunk_cachep) {
if (ocfs2_inode_cachep)
kmem_cache_destroy(ocfs2_inode_cachep);
if (ocfs2_dquot_cachep)
kmem_cache_destroy(ocfs2_dquot_cachep);
if (ocfs2_qf_chunk_cachep)
kmem_cache_destroy(ocfs2_qf_chunk_cachep);
return -ENOMEM; return -ENOMEM;
}
return 0; return 0;
} }
...@@ -1252,8 +1279,15 @@ static void ocfs2_free_mem_caches(void) ...@@ -1252,8 +1279,15 @@ static void ocfs2_free_mem_caches(void)
{ {
if (ocfs2_inode_cachep) if (ocfs2_inode_cachep)
kmem_cache_destroy(ocfs2_inode_cachep); kmem_cache_destroy(ocfs2_inode_cachep);
ocfs2_inode_cachep = NULL; ocfs2_inode_cachep = NULL;
if (ocfs2_dquot_cachep)
kmem_cache_destroy(ocfs2_dquot_cachep);
ocfs2_dquot_cachep = NULL;
if (ocfs2_qf_chunk_cachep)
kmem_cache_destroy(ocfs2_qf_chunk_cachep);
ocfs2_qf_chunk_cachep = NULL;
} }
static int ocfs2_get_sector(struct super_block *sb, static int ocfs2_get_sector(struct super_block *sb,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment