Whamcloud - gitweb
LU-15902 obdclass: dt_try_as_dir() check dir exists
[fs/lustre-release.git] / lustre / quota / lquota_disk.c
index 77e69c8..ac1b220 100644 (file)
@@ -129,7 +129,7 @@ static inline int lquota_disk_slv_filename(const struct lu_fid *glb_fid,
        name++;
 
        /* the filename is composed of the most signicant bits of the global
-        * FID, that's to say the oid which encodes the pool id, pool type and
+        * FID, that's to say the oid which encodes the pool type and
         * quota type, followed by the export UUID */
        sprintf(filename, "0x%x-%s", glb_fid->f_oid, name);
 
@@ -202,7 +202,7 @@ struct dt_object *lquota_disk_dir_find_create(const struct lu_env *env,
        if (IS_ERR(qt_dir))
                GOTO(out, rc = PTR_ERR(qt_dir));
 
-       if (!dt_try_as_dir(env, qt_dir))
+       if (!dt_try_as_dir(env, qt_dir, true))
                GOTO(out, rc = -ENOTDIR);
        EXIT;
 out:
@@ -248,8 +248,7 @@ struct dt_object *lquota_disk_glb_find_create(const struct lu_env *env,
        idx_feat = &dt_quota_glb_features;
 
        /* the filename is composed of the most signicant bits of the FID,
-        * that's to say the oid which encodes the pool id, pool type and quota
-        * type */
+        * that's to say the oid which encodes the pool type and quota type */
        sprintf(qti->qti_buf, "0x%x", fid->f_oid);
 
        if (local) {
@@ -407,7 +406,7 @@ struct dt_object *lquota_disk_slv_find_create(const struct lu_env *env,
        if (local) {
                int pool_type, qtype;
 
-               rc = lquota_extract_fid(glb_fid, NULL, &pool_type, &qtype);
+               rc = lquota_extract_fid(glb_fid, &pool_type, &qtype);
                if (rc)
                        RETURN(ERR_PTR(rc));
 
@@ -542,7 +541,7 @@ int lquota_disk_for_each_slv(const struct lu_env *env, struct dt_object *parent,
                if (qti->qti_fid.f_seq != FID_SEQ_QUOTA)
                        goto next;
 
-               rc = func(env, glb_fid, (char *)key, &qti->qti_fid, arg);
+               rc = func(env, glb_fid, qti->qti_buf, &qti->qti_fid, arg);
                if (rc)
                        break;
 next:
@@ -702,6 +701,36 @@ out:
        return rc;
 }
 
+int lquota_disk_delete(const struct lu_env *env, struct thandle *th,
+                      struct dt_object *obj, __u64 qid, __u64 *ver)
+{
+       struct lquota_thread_info       *qti = lquota_info(env);
+       struct dt_key                   *key = (struct dt_key *)&qid;
+       int                              rc;
+
+       ENTRY;
+
+       LASSERT(dt_object_exists(obj));
+       LASSERT(obj->do_index_ops != NULL);
+
+       /* lock index */
+       dt_write_lock(env, obj, 0);
+
+       /* check whether there is already an existing record for this ID */
+       rc = dt_lookup(env, obj, (struct dt_rec *)&qti->qti_rec, key);
+       if (rc == 0) {
+               rc = dt_delete(env, obj, key, th);
+               if (rc == 0 && ver != NULL) {
+                       *ver = dt_version_get(env, obj);
+                       (*ver)++;
+                       dt_version_set(env, obj, *ver, th);
+               }
+       }
+
+       dt_write_unlock(env, obj);
+       RETURN(rc);
+}
+
 /*
  * Update version of an index file
  *