Whamcloud - gitweb
LU-6245 libcfs: remove prim wrappers for libcfs
[fs/lustre-release.git] / lustre / osd-ldiskfs / osd_quota_fmt.c
index 4dbfa07..482f817 100644 (file)
@@ -21,7 +21,7 @@
  * GPL HEADER END
  */
 /*
- * Copyright (c) 2011, 2012, Whamcloud, Inc.
+ * Copyright (c) 2012, 2014, Intel Corporation.
  * Use is subject to license terms.
  *
  * Lustre administrative quota format.
@@ -40,7 +40,7 @@ static const union
 
 static inline dqbuf_t getdqbuf(void)
 {
-       dqbuf_t buf = cfs_alloc(LUSTRE_DQBLKSIZE, CFS_ALLOC_IO);
+       dqbuf_t buf = kmalloc(LUSTRE_DQBLKSIZE, GFP_NOFS);
        if (!buf)
                CWARN("Not enough memory for quota buffers.\n");
        return buf;
@@ -48,13 +48,11 @@ static inline dqbuf_t getdqbuf(void)
 
 static inline void freedqbuf(dqbuf_t buf)
 {
-       cfs_free(buf);
+       kfree(buf);
 }
 
 /**
  * Read the \a blk into \a buf.
- *
- * TODO Will support enforcement quota later.
  */
 static ssize_t quota_read_blk(const struct lu_env *env,
                              struct osd_object *obj,
@@ -66,6 +64,29 @@ static ssize_t quota_read_blk(const struct lu_env *env,
        ENTRY;
 
        memset(buf, 0, LUSTRE_DQBLKSIZE);
+
+#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 7, 53, 0)
+       /* type is set as -1 when reading old admin quota file */
+       if (type != USRQUOTA && type != GRPQUOTA) {
+               struct lu_buf   lu_buffer;
+               loff_t          pos;
+
+               lu_buffer.lb_buf = buf;
+               lu_buffer.lb_len = LUSTRE_DQBLKSIZE;
+               pos = blk << LUSTRE_DQBLKSIZE_BITS;
+
+               ret = dt_record_read(env, &obj->oo_dt, &lu_buffer, &pos);
+
+               if (ret == 0)
+                       ret = LUSTRE_DQBLKSIZE;
+               else if (ret == -EBADR || ret == -EFAULT)
+                       ret = 0;
+               RETURN(ret);
+       }
+#else
+#warning "remove old quota compatibility code"
+#endif
+
        ret = sb->s_op->quota_read(sb, type, buf, LUSTRE_DQBLKSIZE,
                                   blk << LUSTRE_DQBLKSIZE_BITS);
 
@@ -126,9 +147,10 @@ static loff_t find_block_dqentry(const struct lu_env *env,
                      sizeof(struct lustre_disk_dqdbheader) + i * dqblk_sz;
 
                if (it) {
-                       it->oiq_blk[LUSTRE_DQTREEDEPTH - 1] = blk;
+                       it->oiq_blk[LUSTRE_DQTREEDEPTH] = blk;
                        it->oiq_offset = ret;
                        it->oiq_id = dqid;
+                       it->oiq_index[LUSTRE_DQTREEDEPTH] = i;
                } else {
                        ret = 0;
                }
@@ -158,7 +180,7 @@ loff_t find_tree_dqentry(const struct lu_env *env,
 
        if (!buf)
                RETURN(-ENOMEM);
-       ret = quota_read_blk(env, obj, 0, blk, buf);
+       ret = quota_read_blk(env, obj, type, blk, buf);
        if (ret < 0) {
                CERROR("Can't read quota tree block %u.\n", blk);
                GOTO(out_buf, ret);
@@ -174,8 +196,11 @@ loff_t find_tree_dqentry(const struct lu_env *env,
        else
                ret = find_block_dqentry(env, obj, type, dqid, blk, it);
 
-       if (it && ret > 0) /* Entry found */
-               it->oiq_blk[depth] = blk;
+       if (it && ret > 0) {
+               it->oiq_blk[depth + 1] = blk;
+               it->oiq_index[depth] = GETIDINDEX(dqid, depth);
+       }
+
 out_buf:
        freedqbuf(buf);
        RETURN(ret);
@@ -193,14 +218,21 @@ int walk_block_dqentry(const struct lu_env *env, struct osd_object *obj,
                       int type, uint blk, uint index,
                       struct osd_it_quota *it)
 {
-       dqbuf_t                          buf = getdqbuf();
+       dqbuf_t                          buf;
        loff_t                           ret = 0;
        struct lustre_disk_dqdbheader   *dqhead;
        int                              i, dqblk_sz;
        struct lustre_disk_dqblk_v2     *ddquot;
-
+       struct osd_quota_leaf           *leaf;
        ENTRY;
 
+       /* check if the leaf block has been processed before */
+       list_for_each_entry(leaf, &it->oiq_list, oql_link) {
+               if (leaf->oql_blk == blk)
+                       RETURN(1);
+       }
+
+       buf = getdqbuf();
        dqhead = (struct lustre_disk_dqdbheader *)buf;
        dqblk_sz = sizeof(struct lustre_disk_dqblk_v2);
        if (!buf)
@@ -212,7 +244,7 @@ int walk_block_dqentry(const struct lu_env *env, struct osd_object *obj,
        }
        ret = 1;
 
-       if (!le32_to_cpu(dqhead->dqdh_entries))
+       if (!le16_to_cpu(dqhead->dqdh_entries))
                GOTO(out_buf, ret);
 
        ddquot = (struct lustre_disk_dqblk_v2 *)GETENTRIES(buf);
@@ -223,11 +255,12 @@ int walk_block_dqentry(const struct lu_env *env, struct osd_object *obj,
                            (char *)&ddquot[i], dqblk_sz))
                        continue;
 
-               it->oiq_blk[LUSTRE_DQTREEDEPTH - 1] = blk;
+               it->oiq_blk[LUSTRE_DQTREEDEPTH] = blk;
                it->oiq_id = le32_to_cpu(ddquot[i].dqb_id);
                it->oiq_offset = (blk << LUSTRE_DQBLKSIZE_BITS) +
                                  sizeof(struct lustre_disk_dqdbheader) +
                                  i * dqblk_sz;
+               it->oiq_index[LUSTRE_DQTREEDEPTH] = i;
                ret = 0;
                break;
        }
@@ -276,8 +309,11 @@ int walk_tree_dqentry(const struct lu_env *env, struct osd_object *obj,
                        ret = walk_block_dqentry(env, obj, type, blk, 0, it);
        }
 
-       if (ret == 0) /* Entry found */
-               it->oiq_blk[depth] = blk;
+       if (ret == 0) { /* Entry found */
+               it->oiq_blk[depth + 1] = blk;
+               it->oiq_index[depth] = index;
+       }
+
 out_buf:
        freedqbuf(buf);
        RETURN(ret);