Whamcloud - gitweb
LU-5061 obd: add rnb_ prefix to struct niobuf_remote members
[fs/lustre-release.git] / lustre / osd-ldiskfs / osd_quota.c
index bfab83a..a56f890 100644 (file)
@@ -21,7 +21,7 @@
  * GPL HEADER END
  */
 /*
- * Copyright (c) 2012, Intel Corporation.
+ * Copyright (c) 2012, 2013, Intel Corporation.
  * Use is subject to license terms.
  *
  * Author: Johann Lombardi <johann@whamcloud.com>
@@ -113,11 +113,19 @@ static int osd_acct_index_lookup(const struct lu_env *env,
        struct lquota_acct_rec  *rec = (struct lquota_acct_rec *)dtrec;
        __u64                    id = *((__u64 *)dtkey);
        int                      rc;
+#ifdef HAVE_DQUOT_KQID
+       struct kqid             qid;
+#endif
 
        ENTRY;
 
        memset((void *)dqblk, 0, sizeof(struct obd_dqblk));
+#ifdef HAVE_DQUOT_KQID
+       qid = make_kqid(&init_user_ns, obj2type(dtobj), id);
+       rc = sb->s_qcop->get_dqblk(sb, qid, dqblk);
+#else
        rc = sb->s_qcop->get_dqblk(sb, obj2type(dtobj), (qid_t) id, dqblk);
+#endif
        if (rc)
                RETURN(rc);
 #ifdef HAVE_DQUOT_FS_DISK_QUOTA
@@ -162,7 +170,7 @@ static struct dt_it *osd_it_acct_init(const struct lu_env *env,
        memset(it, 0, sizeof(*it));
        lu_object_get(lo);
        it->oiq_obj = obj;
-       CFS_INIT_LIST_HEAD(&it->oiq_list);
+       INIT_LIST_HEAD(&it->oiq_list);
 
        /* LUSTRE_DQTREEOFF is the initial offset where the tree can be found */
        it->oiq_blk[0] = LUSTRE_DQTREEOFF;
@@ -186,8 +194,8 @@ static void osd_it_acct_fini(const struct lu_env *env, struct dt_it *di)
 
        lu_object_put(env, &it->oiq_obj->oo_dt.do_lu);
 
-       cfs_list_for_each_entry_safe(leaf, tmp, &it->oiq_list, oql_link) {
-               cfs_list_del_init(&leaf->oql_link);
+       list_for_each_entry_safe(leaf, tmp, &it->oiq_list, oql_link) {
+               list_del_init(&leaf->oql_link);
                OBD_FREE_PTR(leaf);
        }
        EXIT;
@@ -254,9 +262,9 @@ static int osd_it_add_processed(struct osd_it_quota *it, int depth)
        OBD_ALLOC_PTR(leaf);
        if (leaf == NULL)
                RETURN(-ENOMEM);
-       CFS_INIT_LIST_HEAD(&leaf->oql_link);
+       INIT_LIST_HEAD(&leaf->oql_link);
        leaf->oql_blk = it->oiq_blk[depth];
-       cfs_list_add_tail(&leaf->oql_link, &it->oiq_list);
+       list_add_tail(&leaf->oql_link, &it->oiq_list);
        RETURN(0);
 }
 
@@ -846,6 +854,8 @@ out:
        return rc;
 }
 
+/* Nobdy else can access the global index now, it's safe to truncate and
+ * reinitialize it */
 static int truncate_quota_index(const struct lu_env *env, struct dt_object *dt,
                                const struct dt_index_features *feat)
 {
@@ -855,8 +865,13 @@ static int truncate_quota_index(const struct lu_env *env, struct dt_object *dt,
        struct osd_thandle      *oth;
        struct inode            *inode;
        int                      rc;
+       struct iam_container    *bag = &(osd_dt_obj(dt))->oo_dir->od_container;
+       struct lu_buf           *lb = &osd_oti_get(env)->oti_buf;
        ENTRY;
 
+       LASSERT(bag->ic_root_bh != NULL);
+       iam_container_fini(bag);
+
        LASSERT(fid_seq(lu_object_fid(&dt->do_lu)) == FID_SEQ_QUOTA_GLB);
 
        OBD_ALLOC_PTR(attr);
@@ -883,7 +898,9 @@ static int truncate_quota_index(const struct lu_env *env, struct dt_object *dt,
        inode = osd_dt_obj(dt)->oo_inode;
        LASSERT(inode);
 
-       rc = dt_declare_record_write(env, dt, inode->i_sb->s_blocksize * 2, 0, th);
+       /* iam_lfix_create() writes two blocks at the beginning */
+       lb->lb_len = osd_sb(osd)->s_blocksize * 2;
+       rc = dt_declare_record_write(env, dt, lb, 0, th);
        if (rc)
                GOTO(out, rc);
 
@@ -917,6 +934,12 @@ out_lock:
 out:
        dt_trans_stop(env, &osd->od_dt_dev, th);
        OBD_FREE_PTR(attr);
+
+       if (rc == 0) {
+               rc  = iam_container_setup(bag);
+               if (rc != 0)
+                       iam_container_fini(bag);
+       }
        RETURN(rc);
 }
 
@@ -956,7 +979,7 @@ int osd_quota_migration(const struct lu_env *env, struct dt_object *dt,
        struct dt_object        *root, *parent = NULL, *admin = NULL;
        dt_obj_version_t         version;
        char                    *fname;
-       bool                     isblk, converted = false;
+       bool                     isblk = false, converted = false;
        int                      rc;
        ENTRY;
 
@@ -1041,7 +1064,7 @@ int osd_quota_migration(const struct lu_env *env, struct dt_object *dt,
        if (rc) {
                CERROR("%s: Failed to truncate the quota index "DFID", rc:%d\n",
                       osd->od_svname, PFID(lu_object_fid(&dt->do_lu)), rc);
-               RETURN(rc);
+               GOTO(out, rc);
        }
 
        /* set up indexing operations for the admin file */