Whamcloud - gitweb
LU-8955 nodemap: add SELinux policy info to nodemap
[fs/lustre-release.git] / lustre / quota / lproc_quota.c
index 1f2584f..a9a3b0b 100644 (file)
@@ -21,7 +21,7 @@
  * GPL HEADER END
  */
 /*
- * Copyright (c) 2011, 2015, Intel Corporation.
+ * Copyright (c) 2011, 2017, Intel Corporation.
  * Use is subject to license terms.
  *
  * Author: Johann Lombardi <johann.lombardi@intel.com>
@@ -165,6 +165,21 @@ static void *lprocfs_quota_seq_next(struct seq_file *p, void *v, loff_t *pos)
        return NULL;
 }
 
+static inline const char *oid2name(__u32 oid)
+{
+       switch (oid) {
+       case ACCT_USER_OID:
+               return "usr_accounting";
+       case ACCT_GROUP_OID:
+               return "grp_accounting";
+       case ACCT_PROJECT_OID:
+               return "prj_accounting";
+               break;
+       default:
+               return "unknown_accounting";
+       }
+}
+
 /*
  * Output example:
  *
@@ -195,10 +210,7 @@ static int lprocfs_quota_seq_show(struct seq_file *p, void *v)
 
        if (v == SEQ_START_TOKEN) {
                if (fid_is_acct(fid)) {
-                       if (fid_oid(fid) == ACCT_USER_OID)
-                               seq_printf(p, "usr_accounting:\n");
-                       else
-                               seq_printf(p, "grp_accounting:\n");
+                       seq_printf(p, "%s:\n", oid2name(fid_oid(fid)));
                } else if (fid_seq(fid) == FID_SEQ_QUOTA_GLB) {
                        int     poolid, rtype, qtype;
 
@@ -207,7 +219,7 @@ static int lprocfs_quota_seq_show(struct seq_file *p, void *v)
                                return rc;
 
                        seq_printf(p, "global_pool%d_%s_%s\n", poolid,
-                                  RES_NAME(rtype), QTYPE_NAME(qtype));
+                                  RES_NAME(rtype), qtype_name(qtype));
                } else if (fid_seq(fid) == FID_SEQ_LOCAL_NAME) {
                        /* global index copy object */
                        seq_printf(p, "global_index_copy:\n");
@@ -296,6 +308,11 @@ static int lprocfs_quota_seq_open(struct inode *inode, struct file *file)
        if (rc)
                goto out_env;
 
+       if (!lqp->lqp_obj) {
+               lqp->lqp_it = NULL;
+               goto out_seq;
+       }
+
        /* initialize iterator */
        iops = &lqp->lqp_obj->do_index_ops->dio_it;
        it = iops->init(&lqp->lqp_env, lqp->lqp_obj, 0);
@@ -310,6 +327,7 @@ static int lprocfs_quota_seq_open(struct inode *inode, struct file *file)
        lqp->lqp_it = it;
        lqp->lqp_cookie = 0;
 
+out_seq:
        seq = file->private_data;
        seq->private = lqp;
        return 0;
@@ -328,9 +346,10 @@ static int lprocfs_quota_seq_release(struct inode *inode, struct file *file)
        const struct dt_it_ops  *iops;
 
        LASSERT(lqp);
-       iops = &lqp->lqp_obj->do_index_ops->dio_it;
-       if (lqp->lqp_it != NULL)
+       if (lqp->lqp_it != NULL) {
+               iops = &lqp->lqp_obj->do_index_ops->dio_it;
                iops->fini(&lqp->lqp_env, lqp->lqp_it);
+       }
        lu_env_fini(&lqp->lqp_env);
        OBD_FREE_PTR(lqp);