Whamcloud - gitweb
b=24037 Changes of 2.6.32 kernel.
[fs/lustre-release.git] / lustre / include / lustre_quota.h
index 5331f7c..ee0ca22 100644 (file)
@@ -26,7 +26,7 @@
  * 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.
  */
 /*
 #ifndef _LUSTRE_QUOTA_H
 #define _LUSTRE_QUOTA_H
 
+/** \defgroup quota quota
+ *
+ * @{
+ */
+
 #if defined(__linux__)
 #include <linux/lustre_quota.h>
 #elif defined(__APPLE__)
@@ -51,7 +56,6 @@
 #include <lustre/lustre_idl.h>
 #include <lvfs.h>
 #include <obd_support.h>
-#include <class_hash.h>
 
 struct obd_device;
 struct client_obd;
@@ -158,10 +162,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 */
@@ -175,11 +175,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_semaphore_t dq_sem;
         /** 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 */
@@ -188,8 +188,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 */
@@ -197,7 +195,7 @@ struct lustre_dquot {
 };
 
 struct dquot_id {
-        struct list_head        di_link;
+        cfs_list_t              di_link;
         __u32                   di_id;
         __u32                   di_flag;
 };
@@ -222,23 +220,12 @@ 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);
 
 typedef int (*dqacq_handler_t) (struct obd_device * obd, struct qunit_data * qd,
                                 int opc);
 
-/*
-#ifdef HAVE_VFS_DQ_OFF
-#define LL_DQUOT_OFF(sb, remount)    vfs_dq_off(sb, remount)
-#else
-#define LL_DQUOT_OFF(sb, remount)    DQUOT_OFF(sb)
-#endif
-*/
-
-#define LL_DQUOT_OFF(sb)    DQUOT_OFF(sb)
-
-
 /* user quota is turned on on filter */
 #define LQC_USRQUOTA_FLAG (1 << 0)
 /* group quota is turned on on filter */
@@ -265,16 +252,12 @@ struct lustre_quota_ctxt {
                                          * 0:Off, 1:On
                                          */
                       lqc_valid:1,      /** this qctxt is valid or not */
-                      lqc_setup:1,      /**
+                      lqc_setup:1;      /**
                                          * tell whether of not quota_type has
                                          * been processed, so that the master
                                          * knows when it can start processing
                                          * incoming acq/rel quota requests
                                          */
-                      lqc_immutable:1;  /**
-                                         * cannot be turned on/off on-fly;
-                                         * temporary used by SOM.
-                                         */
         /** }@ */
         /**
          * original unit size of file quota and
@@ -296,7 +279,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;
 
         /** @{ */
         /**
@@ -331,7 +314,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
@@ -342,7 +325,7 @@ struct lustre_quota_ctxt {
         /** lquota statistics */
         struct lprocfs_stats  *lqc_stats;
         /** the number of used hashed lqs */
-        atomic_t      lqc_lqs;
+        cfs_atomic_t  lqc_lqs;
         /** no lqs are in use */
         cfs_waitq_t   lqc_lqs_waitq;
 };
@@ -351,7 +334,7 @@ struct lustre_quota_ctxt {
 #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;    /** 31st bit is QB_SET, 30th bit is QI_SET
                                      * other bits are same as LQUOTA_FLAGS_*
@@ -373,21 +356,28 @@ 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;
+        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_RECOVERY(lqs)  ((lqs)->lqs_flags |= LQUOTA_FLAGS_RECOVERY)
+#define LQS_SET_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_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,
@@ -396,39 +386,25 @@ struct lustre_qunit_size {
 #define LQS_KEY_ID(key)      (key & 0xffffffff)
 #define LQS_KEY_GRP(key)     (key >> 32)
 
-static inline void __lqs_getref(struct lustre_qunit_size *lqs)
-{
-        int count = atomic_inc_return(&lqs->lqs_refcount);
-
-        if (count == 2) /* quota_create_lqs */
-                atomic_inc(&lqs->lqs_ctxt->lqc_lqs);
-        CDEBUG(D_QUOTA, "lqs=%p refcount %d\n", lqs, count);
-}
-
 static inline void lqs_getref(struct lustre_qunit_size *lqs)
 {
-        __lqs_getref(lqs);
-}
-
-static inline void __lqs_putref(struct lustre_qunit_size *lqs)
-{
-        LASSERT(atomic_read(&lqs->lqs_refcount) > 0);
+        int count = cfs_atomic_inc_return(&lqs->lqs_refcount);
 
-        if (atomic_dec_return(&lqs->lqs_refcount) == 1)
-                if (atomic_dec_and_test(&lqs->lqs_ctxt->lqc_lqs))
-                        cfs_waitq_signal(&lqs->lqs_ctxt->lqc_lqs_waitq);
-        CDEBUG(D_QUOTA, "lqs=%p refcount %d\n",
-               lqs, atomic_read(&lqs->lqs_refcount));
+        CDEBUG(D_INFO, "lqs=%p refcount %d\n", lqs, count);
 }
 
 static inline void lqs_putref(struct lustre_qunit_size *lqs)
 {
-        __lqs_putref(lqs);
-}
+        int count = cfs_atomic_read(&lqs->lqs_refcount);
 
-static inline void lqs_initref(struct lustre_qunit_size *lqs)
-{
-        atomic_set(&lqs->lqs_refcount, 0);
+        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);
+        }
 }
 
 #else
@@ -446,7 +422,7 @@ struct lustre_quota_ctxt {
 
 #else
 
-#define LL_DQUOT_OFF(sb, remount) do {} while(0)
+#define LL_DQUOT_OFF(sb) do {} while(0)
 
 struct lustre_quota_info {
 };
@@ -465,7 +441,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 */
-        struct semaphore    *qta_sem;   /** obt_quotachecking */
+        cfs_semaphore_t     *qta_sem;   /** obt_quotachecking */
 };
 
 struct obd_trans_info;
@@ -559,7 +535,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;
 
@@ -820,4 +797,6 @@ extern quota_interface_t lmv_quota_interface;
         "admin_quotafile_v2.grp"        /** group admin quotafile */\
 }
 
+/** @} quota */
+
 #endif /* _LUSTRE_QUOTA_H */