X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Finclude%2Flustre_quota.h;h=545a3369fc9c2e0a38ed82daf3828e13c78443ed;hb=51435cfffcd6815e70fb46b0ec2edcac3327bf44;hp=6f0105a62e1ceb4ce0351f7c4833e3c3836d951c;hpb=6dc53dbb70e05edeb40ca021b7d3df1203560147;p=fs%2Flustre-release.git diff --git a/lustre/include/lustre_quota.h b/lustre/include/lustre_quota.h index 6f0105a..545a336 100644 --- a/lustre/include/lustre_quota.h +++ b/lustre/include/lustre_quota.h @@ -1,6 +1,4 @@ -/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- - * vim:expandtab:shiftwidth=8:tabstop=8: - * +/* * GPL HEADER START * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. @@ -26,8 +24,10 @@ * GPL HEADER END */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved + * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. + * + * Copyright (c) 2012, Whamcloud, Inc. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -37,6 +37,11 @@ #ifndef _LUSTRE_QUOTA_H #define _LUSTRE_QUOTA_H +/** \defgroup quota quota + * + * @{ + */ + #if defined(__linux__) #include #elif defined(__APPLE__) @@ -47,11 +52,10 @@ #error Unsupported operating system. #endif -#include #include +#include #include #include -#include struct obd_device; struct client_obd; @@ -60,7 +64,25 @@ struct client_obd; #define NR_DQHASH 45 #endif -#ifdef HAVE_QUOTA_SUPPORT +#ifndef QUOTABLOCK_BITS +#define QUOTABLOCK_BITS 10 +#endif + +#ifndef QUOTABLOCK_SIZE +#define QUOTABLOCK_SIZE (1 << QUOTABLOCK_BITS) +#endif + +#ifndef toqb +#define toqb(x) (((x) + QUOTABLOCK_SIZE - 1) >> QUOTABLOCK_BITS) +#endif + +#ifndef MAX_IQ_TIME +#define MAX_IQ_TIME 604800 /* (7*24*60*60) 1 week */ +#endif + +#ifndef MAX_DQ_TIME +#define MAX_DQ_TIME 604800 /* (7*24*60*60) 1 week */ +#endif #ifdef __KERNEL__ @@ -138,10 +160,6 @@ struct lustre_quota_info { lustre_quota_version_t qi_version; }; -#define DQ_STATUS_AVAIL 0x0 /* Available dquot */ -#define DQ_STATUS_SET 0x01 /* Sombody is setting dquot */ -#define DQ_STATUS_RECOVERY 0x02 /* dquot is in recovery */ - struct lustre_mem_dqblk { __u64 dqb_bhardlimit; /**< absolute limit on disk blks alloc */ __u64 dqb_bsoftlimit; /**< preferred limit on disk blks */ @@ -155,11 +173,11 @@ struct lustre_mem_dqblk { struct lustre_dquot { /** Hash list in memory, protect by dquot_hash_lock */ - struct list_head dq_hash; + cfs_list_t dq_hash; /** Protect the data in lustre_dquot */ - struct semaphore dq_sem; + cfs_mutex_t dq_mutex; /** Use count */ - int dq_refcnt; + cfs_atomic_t dq_refcnt; /** Pointer of quota info it belongs to */ struct lustre_quota_info *dq_info; /** Offset of dquot on disk */ @@ -168,8 +186,6 @@ struct lustre_dquot { unsigned int dq_id; /** Type fo quota (USRQUOTA, GRPQUOUTA) */ int dq_type; - /** See DQ_STATUS_ */ - unsigned short dq_status; /** See DQ_ in quota.h */ unsigned long dq_flags; /** Diskquota usage */ @@ -177,9 +193,14 @@ struct lustre_dquot { }; struct dquot_id { - struct list_head di_link; + cfs_list_t di_link; __u32 di_id; + __u32 di_flag; }; +/* set inode quota limitation on a quota uid/gid */ +#define QI_SET (1 << 30) +/* set block quota limitation on a quota uid/gid */ +#define QB_SET (1 << 31) #define QFILE_CHK 1 #define QFILE_RD_INFO 2 @@ -197,11 +218,9 @@ int lustre_read_dquot(struct lustre_dquot *dquot); int lustre_commit_dquot(struct lustre_dquot *dquot); int lustre_init_quota_info(struct lustre_quota_info *lqi, int type); int lustre_get_qids(struct file *file, struct inode *inode, int type, - struct list_head *list); + cfs_list_t *list); int lustre_quota_convert(struct lustre_quota_info *lqi, int type); -#define LL_DQUOT_OFF(sb) DQUOT_OFF(sb) - typedef int (*dqacq_handler_t) (struct obd_device * obd, struct qunit_data * qd, int opc); @@ -258,7 +277,7 @@ struct lustre_quota_ctxt { /** See comment of lqc_itune_sz */ unsigned long lqc_btune_sz; /** all lustre_qunit_size structures */ - struct lustre_hash *lqc_lqs_hash; + cfs_hash_t *lqc_lqs_hash; /** @{ */ /** @@ -293,7 +312,7 @@ struct lustre_quota_ctxt { */ int lqc_sync_blk; /** guard lqc_imp_valid now */ - spinlock_t lqc_lock; + cfs_spinlock_t lqc_lock; /** * when mds isn't connected, threads * on osts who send the quota reqs @@ -303,15 +322,21 @@ struct lustre_quota_ctxt { struct proc_dir_entry *lqc_proc_dir; /** lquota statistics */ struct lprocfs_stats *lqc_stats; + /** the number of used hashed lqs */ + cfs_atomic_t lqc_lqs; + /** no lqs are in use */ + cfs_waitq_t lqc_lqs_waitq; }; #define QUOTA_MASTER_READY(qctxt) (qctxt)->lqc_setup = 1 #define QUOTA_MASTER_UNREADY(qctxt) (qctxt)->lqc_setup = 0 struct lustre_qunit_size { - struct hlist_node lqs_hash; /** the hash entry */ + cfs_hlist_node_t lqs_hash; /** the hash entry */ unsigned int lqs_id; /** id of user/group */ - unsigned long lqs_flags; /** is user/group; FULLBUF or LESSBUF */ + unsigned long lqs_flags; /** 31st bit is QB_SET, 30th bit is QI_SET + * other bits are same as LQUOTA_FLAGS_* + */ unsigned long lqs_iunit_sz; /** Unit size of file quota currently */ /** * Trigger dqacq when available file quota @@ -329,51 +354,57 @@ struct lustre_qunit_size { long long lqs_ino_rec; /** when blocks are allocated/released, this value will record it */ long long lqs_blk_rec; - atomic_t lqs_refcount; + cfs_atomic_t lqs_refcount; cfs_time_t lqs_last_bshrink; /** time of last block shrink */ cfs_time_t lqs_last_ishrink; /** time of last inode shrink */ - spinlock_t lqs_lock; - struct quota_adjust_qunit lqs_key; /** hash key */ + cfs_spinlock_t lqs_lock; + unsigned long long lqs_key; /** hash key */ struct lustre_quota_ctxt *lqs_ctxt; /** quota ctxt */ }; -#define LQS_IS_GRP(lqs) ((lqs)->lqs_flags & LQUOTA_FLAGS_GRP) -#define LQS_IS_ADJBLK(lqs) ((lqs)->lqs_flags & LQUOTA_FLAGS_ADJBLK) -#define LQS_IS_ADJINO(lqs) ((lqs)->lqs_flags & LQUOTA_FLAGS_ADJINO) +#define LQS_IS_GRP(lqs) ((lqs)->lqs_flags & LQUOTA_FLAGS_GRP) +#define LQS_IS_ADJBLK(lqs) ((lqs)->lqs_flags & LQUOTA_FLAGS_ADJBLK) +#define LQS_IS_ADJINO(lqs) ((lqs)->lqs_flags & LQUOTA_FLAGS_ADJINO) +#define LQS_IS_RECOVERY(lqs) ((lqs)->lqs_flags & LQUOTA_FLAGS_RECOVERY) +#define LQS_IS_SETQUOTA(lqs) ((lqs)->lqs_flags & LQUOTA_FLAGS_SETQUOTA) -#define LQS_SET_GRP(lqs) ((lqs)->lqs_flags |= LQUOTA_FLAGS_GRP) -#define LQS_SET_ADJBLK(lqs) ((lqs)->lqs_flags |= LQUOTA_FLAGS_ADJBLK) -#define LQS_SET_ADJINO(lqs) ((lqs)->lqs_flags |= LQUOTA_FLAGS_ADJINO) +#define LQS_SET_GRP(lqs) ((lqs)->lqs_flags |= LQUOTA_FLAGS_GRP) +#define LQS_SET_ADJBLK(lqs) ((lqs)->lqs_flags |= LQUOTA_FLAGS_ADJBLK) +#define LQS_SET_ADJINO(lqs) ((lqs)->lqs_flags |= LQUOTA_FLAGS_ADJINO) +#define LQS_SET_RECOVERY(lqs) ((lqs)->lqs_flags |= LQUOTA_FLAGS_RECOVERY) +#define LQS_SET_SETQUOTA(lqs) ((lqs)->lqs_flags |= LQUOTA_FLAGS_SETQUOTA) + +#define LQS_CLEAR_RECOVERY(lqs) ((lqs)->lqs_flags &= ~LQUOTA_FLAGS_RECOVERY) +#define LQS_CLEAR_SETQUOTA(lqs) ((lqs)->lqs_flags &= ~LQUOTA_FLAGS_SETQUOTA) + +/* In the hash for lustre_qunit_size, the key is decided by + * grp_or_usr and uid/gid, in here, I combine these two values, + * which will make comparing easier and more efficient */ +#define LQS_KEY(is_grp, id) ((is_grp ? 1ULL << 32: 0) + id) +#define LQS_KEY_ID(key) (key & 0xffffffff) +#define LQS_KEY_GRP(key) (key >> 32) static inline void lqs_getref(struct lustre_qunit_size *lqs) { - atomic_inc(&lqs->lqs_refcount); - CDEBUG(D_QUOTA, "lqs=%p refcount %d\n", - lqs, atomic_read(&lqs->lqs_refcount)); + int count = cfs_atomic_inc_return(&lqs->lqs_refcount); + + CDEBUG(D_INFO, "lqs=%p refcount %d\n", lqs, count); } static inline void lqs_putref(struct lustre_qunit_size *lqs) { - LASSERT(atomic_read(&lqs->lqs_refcount) > 0); + int count = cfs_atomic_read(&lqs->lqs_refcount); - /* killing last ref, let's let hash table kill it */ - if (atomic_read(&lqs->lqs_refcount) == 1) { - lustre_hash_del(lqs->lqs_ctxt->lqc_lqs_hash, - &lqs->lqs_key, &lqs->lqs_hash); - OBD_FREE_PTR(lqs); - } else { - atomic_dec(&lqs->lqs_refcount); - CDEBUG(D_QUOTA, "lqs=%p refcount %d\n", - lqs, atomic_read(&lqs->lqs_refcount)); + LASSERT(count > 0); + CDEBUG(D_INFO, "lqs=%p refcount %d\n", lqs, count - 1); + if (cfs_atomic_dec_and_test(&lqs->lqs_refcount)) { + if (cfs_atomic_dec_and_test(&lqs->lqs_ctxt->lqc_lqs)) + cfs_waitq_signal(&lqs->lqs_ctxt->lqc_lqs_waitq); + OBD_FREE_PTR(lqs); } } -static inline void lqs_initref(struct lustre_qunit_size *lqs) -{ - atomic_set(&lqs->lqs_refcount, 0); -} - #else struct lustre_quota_info { @@ -387,18 +418,6 @@ struct lustre_quota_ctxt { #endif /* !__KERNEL__ */ -#else - -#define LL_DQUOT_OFF(sb) do {} while(0) - -struct lustre_quota_info { -}; - -struct lustre_quota_ctxt { -}; - -#endif /* !HAVE_QUOTA_SUPPORT */ - /* If the (quota limit < qunit * slave count), the slave which can't * acquire qunit should set it's local limit as MIN_QLIMIT */ #define MIN_QLIMIT 1 @@ -408,7 +427,7 @@ struct quotacheck_thread_args { struct obd_device *qta_obd; /** obd device */ struct obd_quotactl qta_oqctl; /** obd_quotactl args */ struct super_block *qta_sb; /** obd super block */ - atomic_t *qta_sem; /** obt_quotachecking */ + cfs_semaphore_t *qta_sem; /** obt_quotachecking */ }; struct obd_trans_info; @@ -469,10 +488,10 @@ typedef struct { * can finish a block_write or inode_create rpc. It updates the pending * record of block and inode, acquires quota if necessary */ - int (*quota_chkquota) (struct obd_device *, const unsigned int [], - int [], int, quota_acquire, - struct obd_trans_info *, int, struct inode *, - int); + int (*quota_chkquota) (struct obd_device *, struct obd_export *, + const unsigned int [], int [], + int, quota_acquire, struct obd_trans_info *, + int, struct inode *, int); /** * For quota client, the actions after the pending write is committed @@ -502,7 +521,8 @@ typedef struct { */ int (*quota_adjust_qunit) (struct obd_export *exp, struct quota_adjust_qunit *oqaq, - struct lustre_quota_ctxt *qctxt); + struct lustre_quota_ctxt *qctxt, + struct ptlrpc_request_set *rqset); } quota_interface_t; @@ -623,41 +643,6 @@ static inline int lquota_adjust(quota_interface_t *interface, RETURN(ret); } -static inline int lquota_chkdq(quota_interface_t *interface, - struct client_obd *cli, const unsigned int qid[]) -{ - int rc; - ENTRY; - - QUOTA_CHECK_OP(interface, chkdq); - rc = QUOTA_OP(interface, chkdq)(cli, qid); - RETURN(rc); -} - -static inline int lquota_setdq(quota_interface_t *interface, - struct client_obd *cli, const unsigned int qid[], - obd_flag valid, obd_flag flags) -{ - int rc; - ENTRY; - - QUOTA_CHECK_OP(interface, setdq); - rc = QUOTA_OP(interface, setdq)(cli, qid, valid, flags); - RETURN(rc); -} - -static inline int lquota_poll_check(quota_interface_t *interface, - struct obd_export *exp, - struct if_quotacheck *qchk) -{ - int rc; - ENTRY; - - QUOTA_CHECK_OP(interface, poll_check); - rc = QUOTA_OP(interface, poll_check)(exp, qchk); - RETURN(rc); -} - static inline int lquota_setinfo(quota_interface_t *interface, struct obd_device *obd, void *data) @@ -708,6 +693,7 @@ static inline int lquota_getflag(quota_interface_t *interface, #ifdef __KERNEL__ static inline int lquota_chkquota(quota_interface_t *interface, struct obd_device *obd, + struct obd_export *exp, const unsigned int id[], int pending[], int count, struct obd_trans_info *oti, int isblk, void *data, int frags) @@ -717,7 +703,7 @@ static inline int lquota_chkquota(quota_interface_t *interface, QUOTA_CHECK_OP(interface, chkquota); QUOTA_CHECK_OP(interface, acquire); - rc = QUOTA_OP(interface, chkquota)(obd, id, pending, count, + rc = QUOTA_OP(interface, chkquota)(obd, exp, id, pending, count, QUOTA_OP(interface, acquire), oti, isblk, (struct inode *)data, frags); RETURN(rc); @@ -738,11 +724,6 @@ static inline int lquota_pending_commit(quota_interface_t *interface, #endif #ifndef __KERNEL__ -extern quota_interface_t osc_quota_interface; -extern quota_interface_t lov_quota_interface; -extern quota_interface_t mdc_quota_interface; -extern quota_interface_t lmv_quota_interface; - #ifndef MAXQUOTAS #define MAXQUOTAS 2 #endif @@ -762,4 +743,48 @@ extern quota_interface_t lmv_quota_interface; "admin_quotafile_v2.grp" /** group admin quotafile */\ } +/* + * Definitions of structures for vfsv0 quota format + * Source linux/fs/quota/quotaio_v2.h + * + * The following definitions are normally found in private kernel headers. + * However, some sites build Lustre against kernel development headers rather + * than than full kernel source, so we provide them here for compatibility. + */ +#ifdef __KERNEL__ +# if !defined(HAVE_QUOTAIO_H) && !defined(HAVE_FS_QUOTA_QUOTAIO_H) && \ + !defined(HAVE_FS_QUOTAIO_H) + +#include +#include + +#define V2_INITQMAGICS {\ + 0xd9c01f11, /* USRQUOTA */\ + 0xd9c01927 /* GRPQUOTA */\ +} + +/* Header with type and version specific information */ +struct v2_disk_dqinfo { + __le32 dqi_bgrace; /* Time before block soft limit becomes hard limit */ + __le32 dqi_igrace; /* Time before inode soft limit becomes hard limit */ + __le32 dqi_flags; /* Flags for quotafile (DQF_*) */ + __le32 dqi_blocks; /* Number of blocks in file */ + __le32 dqi_free_blk; /* Number of first free block in the list */ + __le32 dqi_free_entry; /* Number of block with at least one free entry */ +}; + +/* First generic header */ +struct v2_disk_dqheader { + __le32 dqh_magic; /* Magic number identifying file */ + __le32 dqh_version; /* File version */ +}; +#define V2_DQINFOOFF sizeof(struct v2_disk_dqheader) /* Offset of info header in file */ +#define QT_TREEOFF 1 /* Offset of tree in file in blocks */ +#define V2_DQTREEOFF QT_TREEOFF + +# endif /* !defined(HAVE_QUOTAIO_V1_H) ... */ +#endif /* __KERNEL__ */ + +/** @} quota */ + #endif /* _LUSTRE_QUOTA_H */