Whamcloud - gitweb
LU-1842 quota: zfs local enforcement
[fs/lustre-release.git] / lustre / lvfs / lustre_quota_fmt.c
index f675e4b..82636c8 100644 (file)
@@ -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,7 +24,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.
  */
 /*
  * from linux/fs/quota_v2.c
  */
 
-#ifndef EXPORT_SYMTAB
-# define EXPORT_SYMTAB
-#endif
-
 #include <linux/errno.h>
 #include <linux/fs.h>
 #include <linux/mount.h>
@@ -103,15 +97,8 @@ int check_quota_file(struct file *f, struct inode *inode, int type,
         static const uint quota_magics[] = LUSTRE_INITQMAGICS;
         const uint *quota_versions = lustre_initqversions[version];
 
-        if (!f && !inode) {
-                CERROR("check_quota_file failed!\n");
-                libcfs_debug_dumpstack(NULL);
-                return -EINVAL;
-        }
-
         size = lustre_read_quota(f, inode, type, (char *)&dqhead,
                                  sizeof(struct lustre_disk_dqheader), 0);
-
         if (size != sizeof(struct lustre_disk_dqheader))
                 return -EINVAL;
         if (le32_to_cpu(dqhead.dqh_magic) != quota_magics[type] ||
@@ -128,6 +115,7 @@ int lustre_check_quota_file(struct lustre_quota_info *lqi, int type)
         struct file *f = lqi->qi_files[type];
         return check_quota_file(f, NULL, type, lqi->qi_version);
 }
+EXPORT_SYMBOL(lustre_check_quota_file);
 
 int lustre_read_quota_file_info(struct file* f, struct lustre_mem_dqinfo* info)
 {
@@ -160,6 +148,7 @@ int lustre_read_quota_info(struct lustre_quota_info *lqi, int type)
         return lustre_read_quota_file_info(lqi->qi_files[type],
                                            &lqi->qi_info[type]);
 }
+EXPORT_SYMBOL(lustre_read_quota_info);
 
 /**
  * Write information header to quota file
@@ -184,13 +173,14 @@ int lustre_write_quota_info(struct lustre_quota_info *lqi, int type)
                                   LUSTRE_DQINFOOFF);
 
         if (size != sizeof(struct lustre_disk_dqinfo)) {
-                CDEBUG(D_WARNING, 
+                CDEBUG(D_WARNING,
                        "Can't write info structure on device %s.\n",
                        f->f_vfsmnt->mnt_sb->s_id);
                 return -1;
         }
         return 0;
 }
+EXPORT_SYMBOL(lustre_write_quota_info);
 
 void disk2memdqb(struct lustre_mem_dqblk *m, void *d,
                  lustre_quota_version_t version)
@@ -271,7 +261,7 @@ ssize_t write_blk(struct file *filp, uint blk, dqbuf_t buf)
 
 void lustre_mark_info_dirty(struct lustre_mem_dqinfo *info)
 {
-        set_bit(DQF_INFO_DIRTY_B, &info->dqi_flags);
+        cfs_set_bit(DQF_INFO_DIRTY_B, &info->dqi_flags);
 }
 
 /**
@@ -806,7 +796,7 @@ out_buf:
 /**
  * Find entry for given id in the tree - wrapper function
  */
-static inline loff_t find_dqentry(struct lustre_dquot *dquot, 
+static inline loff_t find_dqentry(struct lustre_dquot *dquot,
                                   lustre_quota_version_t version)
 {
         return find_tree_dqentry(dquot, LUSTRE_DQTREEOFF, 0, version);
@@ -837,7 +827,7 @@ int lustre_read_dquot(struct lustre_dquot *dquot)
                                "VFS: Can't read quota structure for id %u.\n",
                                dquot->dq_id);
                 dquot->dq_off = 0;
-                set_bit(DQ_FAKE_B, &dquot->dq_flags);
+                cfs_set_bit(DQ_FAKE_B, &dquot->dq_flags);
                 memset(&dquot->dq_dqb, 0, sizeof(struct lustre_mem_dqblk));
                 ret = offset;
         } else {
@@ -864,6 +854,7 @@ int lustre_read_dquot(struct lustre_dquot *dquot)
 
         return ret;
 }
+EXPORT_SYMBOL(lustre_read_dquot);
 
 /**
  * Commit changes of dquot to disk - it might also mean deleting
@@ -875,22 +866,28 @@ int lustre_commit_dquot(struct lustre_dquot *dquot)
         lustre_quota_version_t version = dquot->dq_info->qi_version;
         void *handle;
         struct inode *inode = dquot->dq_info->qi_files[dquot->dq_type]->f_dentry->d_inode;
+        int delete = 0;
 
         /* always clear the flag so we don't loop on an IO error... */
-        clear_bit(DQ_MOD_B, &dquot->dq_flags);
+        cfs_clear_bit(DQ_MOD_B, &dquot->dq_flags);
 
         /* The block/inode usage in admin quotafile isn't the real usage
          * over all cluster, so keep the fake dquot entry on disk is
          * meaningless, just remove it */
-        if (test_bit(DQ_FAKE_B, &dquot->dq_flags)) {
-                handle = lustre_quota_journal_start(inode, 1);
+        if (cfs_test_bit(DQ_FAKE_B, &dquot->dq_flags))
+                delete = 1;
+        handle = lustre_quota_journal_start(inode, delete);
+        if (unlikely(IS_ERR(handle))) {
+                rc = PTR_ERR(handle);
+                CERROR("fail to lustre_quota_journal_start: rc = %d\n", rc);
+                return rc;
+        }
+
+        if (delete)
                 rc = lustre_delete_dquot(dquot, version);
-                lustre_quota_journal_stop(handle);
-        } else {
-                handle = lustre_quota_journal_start(inode, 0);
+        else
                 rc = lustre_write_dquot(dquot, version);
-                lustre_quota_journal_stop(handle);
-        }
+        lustre_quota_journal_stop(handle);
 
         if (rc < 0)
                 return rc;
@@ -900,6 +897,7 @@ int lustre_commit_dquot(struct lustre_dquot *dquot)
 
         return rc;
 }
+EXPORT_SYMBOL(lustre_commit_dquot);
 
 int lustre_init_quota_header(struct lustre_quota_info *lqi, int type,
                              int fakemagics)
@@ -954,9 +952,10 @@ int lustre_init_quota_info(struct lustre_quota_info *lqi, int type)
 {
         return lustre_init_quota_info_generic(lqi, type, 0);
 }
+EXPORT_SYMBOL(lustre_init_quota_info);
 
 static int walk_block_dqentry(struct file *filp, struct inode *inode, int type,
-                              uint blk, struct list_head *list)
+                              uint blk, cfs_list_t *list)
 {
         dqbuf_t buf = getdqbuf();
         loff_t ret = 0;
@@ -964,7 +963,7 @@ static int walk_block_dqentry(struct file *filp, struct inode *inode, int type,
             (struct lustre_disk_dqdbheader *)buf;
         struct dqblk *blk_item;
         struct dqblk *pos;
-        struct list_head *tmp;
+        cfs_list_t *tmp;
 
         if (!buf)
                 return -ENOMEM;
@@ -977,12 +976,12 @@ static int walk_block_dqentry(struct file *filp, struct inode *inode, int type,
         if (!le32_to_cpu(dqhead->dqdh_entries))
                 goto out_buf;
 
-        if (list_empty(list)) {
+        if (cfs_list_empty(list)) {
                 tmp = list;
                 goto done;
         }
 
-        list_for_each_entry(pos, list, link) {
+        cfs_list_for_each_entry(pos, list, link) {
                 if (blk == pos->blk)    /* we got this blk already */
                         goto out_buf;
                 if (blk > pos->blk)
@@ -997,9 +996,9 @@ done:
                 goto out_buf;
         }
         blk_item->blk = blk;
-        INIT_LIST_HEAD(&blk_item->link);
+        CFS_INIT_LIST_HEAD(&blk_item->link);
 
-        list_add_tail(&blk_item->link, tmp);
+        cfs_list_add_tail(&blk_item->link, tmp);
 
 out_buf:
         freedqbuf(buf);
@@ -1007,7 +1006,7 @@ out_buf:
 }
 
 int walk_tree_dqentry(struct file *filp, struct inode *inode, int type, 
-                      uint blk, int depth, struct list_head *list)
+                      uint blk, int depth, cfs_list_t *list)
 {
         dqbuf_t buf = getdqbuf();
         loff_t ret = 0;
@@ -1042,9 +1041,9 @@ out_buf:
  * Walk through the quota file (v2 format) to get all ids with quota limit
  */
 int lustre_get_qids(struct file *fp, struct inode *inode, int type,
-                    struct list_head *list)
+                    cfs_list_t *list)
 {
-        struct list_head blk_list;
+        cfs_list_t blk_list;
         struct dqblk *blk_item, *tmp;
         dqbuf_t buf = NULL;
         struct lustre_disk_dqblk_v2 *ddquot;
@@ -1062,18 +1061,18 @@ int lustre_get_qids(struct file *fp, struct inode *inode, int type,
                 RETURN(-EINVAL);
         }
 
-        if (!list_empty(list)) {
+        if (!cfs_list_empty(list)) {
                 CDEBUG(D_ERROR, "not empty list\n");
                 RETURN(-EINVAL);
         }
 
-        INIT_LIST_HEAD(&blk_list);
+        CFS_INIT_LIST_HEAD(&blk_list);
         rc = walk_tree_dqentry(fp, inode, type, LUSTRE_DQTREEOFF, 0, &blk_list);
         if (rc) {
                 CDEBUG(D_ERROR, "walk through quota file failed!(%d)\n", rc);
                 GOTO(out_free, rc);
         }
-        if (list_empty(&blk_list))
+        if (cfs_list_empty(&blk_list))
                 RETURN(0);
 
         buf = getdqbuf();
@@ -1081,7 +1080,7 @@ int lustre_get_qids(struct file *fp, struct inode *inode, int type,
                 RETURN(-ENOMEM);
         ddquot = (struct lustre_disk_dqblk_v2 *)GETENTRIES(buf, version);
 
-        list_for_each_entry(blk_item, &blk_list, link) {
+        cfs_list_for_each_entry(blk_item, &blk_list, link) {
                 loff_t ret = 0;
                 int i, dqblk_sz = lustre_disk_dqblk_sz[version];
 
@@ -1099,7 +1098,7 @@ int lustre_get_qids(struct file *fp, struct inode *inode, int type,
                                     (char *)&ddquot[i], dqblk_sz))
                                 continue;
 
-                        OBD_ALLOC_GFP(dqid, sizeof(*dqid), GFP_NOFS);
+                       OBD_ALLOC_GFP(dqid, sizeof(*dqid), CFS_ALLOC_NOFS);
                         if (!dqid)
                                 GOTO(out_free, rc = -ENOMEM);
 
@@ -1109,14 +1108,14 @@ int lustre_get_qids(struct file *fp, struct inode *inode, int type,
                         dqid->di_flag |= le64_to_cpu(ddquot[i].dqb_bhardlimit) ?
                                          QB_SET : 0;
 
-                        INIT_LIST_HEAD(&dqid->di_link);
-                        list_add(&dqid->di_link, list);
+                        CFS_INIT_LIST_HEAD(&dqid->di_link);
+                        cfs_list_add(&dqid->di_link, list);
                 }
         }
 
 out_free:
-        list_for_each_entry_safe(blk_item, tmp, &blk_list, link) {
-                list_del_init(&blk_item->link);
+        cfs_list_for_each_entry_safe(blk_item, tmp, &blk_list, link) {
+                cfs_list_del_init(&blk_item->link);
                 kfree(blk_item);
         }
         if (buf)
@@ -1124,13 +1123,5 @@ out_free:
 
         RETURN(rc);
 }
-
-
-EXPORT_SYMBOL(lustre_read_quota_info);
-EXPORT_SYMBOL(lustre_write_quota_info);
-EXPORT_SYMBOL(lustre_check_quota_file);
-EXPORT_SYMBOL(lustre_read_dquot);
-EXPORT_SYMBOL(lustre_commit_dquot);
-EXPORT_SYMBOL(lustre_init_quota_info);
 EXPORT_SYMBOL(lustre_get_qids);
 #endif