Whamcloud - gitweb
LU-5560 llite: basic support of SELinux in CLIO
[fs/lustre-release.git] / lustre / lfsck / lfsck_lib.c
index 62b1d8d..178aa3a 100644 (file)
@@ -30,6 +30,7 @@
 
 #define DEBUG_SUBSYSTEM S_LFSCK
 
+#include <linux/kthread.h>
 #include <libcfs/list.h>
 #include <lu_object.h>
 #include <dt_object.h>
@@ -148,7 +149,7 @@ static void lfsck_tgt_descs_fini(struct lfsck_tgt_descs *ltds)
        }
 
        cfs_foreach_bit(ltds->ltd_tgts_bitmap, idx) {
-               ltd = LTD_TGT(ltds, idx);
+               ltd = lfsck_ltd2tgt(ltds, idx);
                if (likely(ltd != NULL)) {
                        LASSERT(list_empty(&ltd->ltd_layout_list));
                        LASSERT(list_empty(&ltd->ltd_layout_phase_list));
@@ -157,7 +158,7 @@ static void lfsck_tgt_descs_fini(struct lfsck_tgt_descs *ltds)
 
                        ltds->ltd_tgtnr--;
                        cfs_bitmap_clear(ltds->ltd_tgts_bitmap, idx);
-                       LTD_TGT(ltds, idx) = NULL;
+                       lfsck_assign_tgt(ltds, NULL, idx);
                        lfsck_tgt_put(ltd);
                }
        }
@@ -229,7 +230,7 @@ static int __lfsck_add_target(const struct lu_env *env,
                        GOTO(unlock, rc = -ENOMEM);
        }
 
-       LTD_TGT(ltds, index) = ltd;
+       lfsck_assign_tgt(ltds, ltd, index);
        cfs_bitmap_set(ltds->ltd_tgts_bitmap, index);
        ltds->ltd_tgtnr++;
 
@@ -598,8 +599,7 @@ static int lfsck_lpf_remove_name_entry(const struct lu_env *env,
        if (rc != 0)
                GOTO(stop, rc);
 
-       rc = dt_delete(env, parent, (const struct dt_key *)name, th,
-                      BYPASS_CAPA);
+       rc = dt_delete(env, parent, (const struct dt_key *)name, th);
        if (rc != 0)
                GOTO(stop, rc);
 
@@ -710,14 +710,14 @@ static int lfsck_create_lpf_local(const struct lu_env *env,
        /* 1b.2. insert dot into child dir */
        rec->rec_fid = cfid;
        rc = dt_insert(env, child, (const struct dt_rec *)rec,
-                      (const struct dt_key *)dot, th, BYPASS_CAPA, 1);
+                      (const struct dt_key *)dot, th, 1);
        if (rc != 0)
                GOTO(unlock, rc);
 
        /* 1b.3. insert dotdot into child dir */
        rec->rec_fid = &LU_LPF_FID;
        rc = dt_insert(env, child, (const struct dt_rec *)rec,
-                      (const struct dt_key *)dotdot, th, BYPASS_CAPA, 1);
+                      (const struct dt_key *)dotdot, th, 1);
        if (rc != 0)
                GOTO(unlock, rc);
 
@@ -728,7 +728,7 @@ static int lfsck_create_lpf_local(const struct lu_env *env,
 
        /* 3b. insert linkEA for child. */
        rc = dt_xattr_set(env, child, &linkea_buf,
-                         XATTR_NAME_LINK, 0, th, BYPASS_CAPA);
+                         XATTR_NAME_LINK, 0, th);
        dt_write_unlock(env, child);
        if (rc != 0)
                GOTO(stop, rc);
@@ -736,7 +736,7 @@ static int lfsck_create_lpf_local(const struct lu_env *env,
        /* 4b. insert name into parent dir */
        rec->rec_fid = cfid;
        rc = dt_insert(env, parent, (const struct dt_rec *)rec,
-                      (const struct dt_key *)name, th, BYPASS_CAPA, 1);
+                      (const struct dt_key *)name, th, 1);
        if (rc != 0)
                GOTO(stop, rc);
 
@@ -865,14 +865,14 @@ static int lfsck_create_lpf_remote(const struct lu_env *env,
        rec->rec_type = S_IFDIR;
        rec->rec_fid = cfid;
        rc = dt_insert(env, child, (const struct dt_rec *)rec,
-                      (const struct dt_key *)dot, th, BYPASS_CAPA, 1);
+                      (const struct dt_key *)dot, th, 1);
        if (rc != 0)
                GOTO(unlock, rc);
 
        /* 1b.3. insert dotdot into child dir */
        rec->rec_fid = &LU_LPF_FID;
        rc = dt_insert(env, child, (const struct dt_rec *)rec,
-                      (const struct dt_key *)dotdot, th, BYPASS_CAPA, 1);
+                      (const struct dt_key *)dotdot, th, 1);
        if (rc != 0)
                GOTO(unlock, rc);
 
@@ -883,7 +883,7 @@ static int lfsck_create_lpf_remote(const struct lu_env *env,
 
        /* 3b. insert linkEA for child */
        rc = dt_xattr_set(env, child, &linkea_buf,
-                         XATTR_NAME_LINK, 0, th, BYPASS_CAPA);
+                         XATTR_NAME_LINK, 0, th);
        if (rc != 0)
                GOTO(unlock, rc);
 
@@ -925,7 +925,7 @@ static int lfsck_create_lpf_remote(const struct lu_env *env,
 
        /* 5b. insert name into parent dir */
        rc = dt_insert(env, parent, (const struct dt_rec *)rec,
-                      (const struct dt_key *)name, th, BYPASS_CAPA, 1);
+                      (const struct dt_key *)name, th, 1);
        if (rc != 0)
                GOTO(stop, rc);
 
@@ -997,7 +997,7 @@ static int lfsck_create_lpf(const struct lu_env *env,
                 * the lfsck_bookmark::lb_lpf_fid successfully. So need lookup
                 * it from MDT0 firstly. */
                rc = dt_lookup(env, parent, (struct dt_rec *)cfid,
-                              (const struct dt_key *)name, BYPASS_CAPA);
+                              (const struct dt_key *)name);
                if (rc != 0 && rc != -ENOENT)
                        GOTO(unlock, rc);
 
@@ -1075,7 +1075,7 @@ static int lfsck_scan_lpf_bad_entries(const struct lu_env *env,
        int                      rc;
        ENTRY;
 
-       it = iops->init(env, parent, LUDA_64BITHASH, BYPASS_CAPA);
+       it = iops->init(env, parent, LUDA_64BITHASH);
        if (IS_ERR(it))
                RETURN(PTR_ERR(it));
 
@@ -1206,7 +1206,7 @@ static int lfsck_verify_lpf_pairs(const struct lu_env *env,
 
        fid_zero(fid);
        rc = dt_lookup(env, child, (struct dt_rec *)fid,
-                      (const struct dt_key *)dotdot, BYPASS_CAPA);
+                      (const struct dt_key *)dotdot);
        if (rc != 0)
                GOTO(linkea, rc);
 
@@ -1292,7 +1292,7 @@ linkea:
        }
 
        rc = dt_lookup(env, parent2, (struct dt_rec *)fid,
-                      (const struct dt_key *)name2, BYPASS_CAPA);
+                      (const struct dt_key *)name2);
        dt_read_unlock(env, child);
        lfsck_ibits_unlock(&lh, LCK_PR);
        if (rc != 0 && rc != -ENOENT)
@@ -1453,7 +1453,7 @@ int lfsck_verify_lpf(const struct lu_env *env, struct lfsck_instance *lfsck)
 find_child2:
        snprintf(name, 8, "MDT%04x", node);
        rc = dt_lookup(env, parent, (struct dt_rec *)cfid,
-                      (const struct dt_key *)name, BYPASS_CAPA);
+                      (const struct dt_key *)name);
        if (rc == -ENOENT) {
                if (!fid_is_zero(&bk->lb_lpf_fid))
                        goto check_child1;
@@ -1719,8 +1719,11 @@ int lfsck_bits_dump(struct seq_file *m, int bits, const char *names[],
        int flag;
        int i;
        bool newline = (bits != 0 ? false : true);
+       int rc;
 
-       seq_printf(m, "%s:%c", prefix, bits != 0 ? ' ' : '\n');
+       rc = seq_printf(m, "%s:%c", prefix, bits != 0 ? ' ' : '\n');
+       if (rc < 0)
+               return rc;
 
        for (i = 0, flag = 1; bits != 0; i++, flag = 1 << i) {
                if (flag & bits) {
@@ -1729,25 +1732,38 @@ int lfsck_bits_dump(struct seq_file *m, int bits, const char *names[],
                                if (bits == 0)
                                        newline = true;
 
-                               seq_printf(m, "%s%c", names[i],
-                                          newline ? '\n' : ',');
+                               rc = seq_printf(m, "%s%c", names[i],
+                                               newline ? '\n' : ',');
+                               if (rc < 0)
+                                       return rc;
                        }
                }
        }
 
        if (!newline)
-               seq_printf(m, "\n");
-       return 0;
+               rc = seq_printf(m, "\n");
+
+       return rc;
 }
 
-int lfsck_time_dump(struct seq_file *m, __u64 time, const char *prefix)
+int lfsck_time_dump(struct seq_file *m, __u64 time, const char *name)
 {
-       if (time != 0)
-               seq_printf(m, "%s: "LPU64" seconds\n", prefix,
-                         cfs_time_current_sec() - time);
-       else
-               seq_printf(m, "%s: N/A\n", prefix);
-       return 0;
+       int rc;
+
+       if (time == 0) {
+               rc = seq_printf(m, "%s_time: N/A\n", name);
+               if (rc == 0)
+                       rc = seq_printf(m, "time_since_%s: N/A\n", name);
+
+               return rc;
+       }
+
+       rc = seq_printf(m, "%s_time: "LPU64"\n", name, time);
+       if (rc == 0)
+               rc = seq_printf(m, "time_since_%s: "LPU64" seconds\n",
+                               name, cfs_time_current_sec() - time);
+
+       return rc;
 }
 
 int lfsck_pos_dump(struct seq_file *m, struct lfsck_position *pos,
@@ -1755,17 +1771,15 @@ int lfsck_pos_dump(struct seq_file *m, struct lfsck_position *pos,
 {
        if (fid_is_zero(&pos->lp_dir_parent)) {
                if (pos->lp_oit_cookie == 0)
-                       seq_printf(m, "%s: N/A, N/A, N/A\n",
-                                  prefix);
-               else
-                       seq_printf(m, "%s: "LPU64", N/A, N/A\n",
-                                  prefix, pos->lp_oit_cookie);
-       } else {
-               seq_printf(m, "%s: "LPU64", "DFID", "LPX64"\n",
-                          prefix, pos->lp_oit_cookie,
-                          PFID(&pos->lp_dir_parent), pos->lp_dir_cookie);
+                       return seq_printf(m, "%s: N/A, N/A, N/A\n", prefix);
+
+               return seq_printf(m, "%s: "LPU64", N/A, N/A\n",
+                                 prefix, pos->lp_oit_cookie);
        }
-       return 0;
+
+       return seq_printf(m, "%s: "LPU64", "DFID", "LPX64"\n",
+                         prefix, pos->lp_oit_cookie,
+                         PFID(&pos->lp_dir_parent), pos->lp_dir_cookie);
 }
 
 void lfsck_pos_fill(const struct lu_env *env, struct lfsck_instance *lfsck,
@@ -1930,6 +1944,56 @@ lfsck_assistant_data_init(struct lfsck_assistant_operations *lao,
        return lad;
 }
 
+struct lfsck_assistant_object *
+lfsck_assistant_object_init(const struct lu_env *env, const struct lu_fid *fid,
+                           const struct lu_attr *attr, __u64 cookie,
+                           bool is_dir)
+{
+       struct lfsck_assistant_object   *lso;
+
+       OBD_ALLOC_PTR(lso);
+       if (lso == NULL)
+               return ERR_PTR(-ENOMEM);
+
+       lso->lso_fid = *fid;
+       if (attr != NULL)
+               lso->lso_attr = *attr;
+
+       atomic_set(&lso->lso_ref, 1);
+       lso->lso_oit_cookie = cookie;
+       if (is_dir)
+               lso->lso_is_dir = 1;
+
+       return lso;
+}
+
+struct dt_object *
+lfsck_assistant_object_load(const struct lu_env *env,
+                           struct lfsck_instance *lfsck,
+                           struct lfsck_assistant_object *lso)
+{
+       struct dt_object *obj;
+
+       obj = lfsck_object_find_bottom(env, lfsck, &lso->lso_fid);
+       if (IS_ERR(obj))
+               return obj;
+
+       if (unlikely(!dt_object_exists(obj) || lfsck_is_dead_obj(obj))) {
+               lso->lso_dead = 1;
+               lfsck_object_put(env, obj);
+
+               return ERR_PTR(-ENOENT);
+       }
+
+       if (lso->lso_is_dir && unlikely(!dt_try_as_dir(env, obj))) {
+               lfsck_object_put(env, obj);
+
+               return ERR_PTR(-ENOTDIR);
+       }
+
+       return obj;
+}
+
 /**
  * Generic LFSCK asynchronous communication interpretor function.
  * The LFSCK RPC reply for both the event notification and status
@@ -2336,6 +2400,7 @@ int lfsck_start_assistant(const struct lu_env *env, struct lfsck_component *com,
        lad->lad_to_double_scan = 0;
        lad->lad_in_double_scan = 0;
        lad->lad_exit = 0;
+       lad->lad_advance_lock = false;
        thread_set_flags(athread, 0);
 
        lta = lfsck_thread_args_init(lfsck, com, lsp);
@@ -2372,9 +2437,6 @@ int lfsck_checkpoint_generic(const struct lu_env *env,
        struct ptlrpc_thread            *athread = &lad->lad_thread;
        struct l_wait_info               lwi     = { 0 };
 
-       if (com->lc_new_checked == 0)
-               return LFSCK_CHECKPOINT_SKIP;
-
        l_wait_event(mthread->t_ctl_waitq,
                     list_empty(&lad->lad_req_list) ||
                     !thread_is_running(mthread) ||
@@ -3244,7 +3306,7 @@ int lfsck_register(const struct lu_env *env, struct dt_device *key,
 
                        rc = dt_lookup(env, root,
                                (struct dt_rec *)(&lfsck->li_global_root_fid),
-                               (const struct dt_key *)"ROOT", BYPASS_CAPA);
+                               (const struct dt_key *)"ROOT");
                        if (rc != 0)
                                GOTO(out, rc);
 
@@ -3256,7 +3318,7 @@ int lfsck_register(const struct lu_env *env, struct dt_device *key,
                                GOTO(out, rc = -ENOTDIR);
 
                        rc = dt_lookup(env, obj, (struct dt_rec *)fid,
-                               (const struct dt_key *)dotlustre, BYPASS_CAPA);
+                               (const struct dt_key *)dotlustre);
                        if (rc != 0)
                                GOTO(out, rc);
 
@@ -3277,8 +3339,7 @@ int lfsck_register(const struct lu_env *env, struct dt_device *key,
 
                        *pfid = *fid;
                        rc = dt_lookup(env, obj, (struct dt_rec *)fid,
-                                      (const struct dt_key *)lostfound,
-                                      BYPASS_CAPA);
+                                      (const struct dt_key *)lostfound);
                        if (rc != 0)
                                GOTO(out, rc);
 
@@ -3451,7 +3512,7 @@ void lfsck_del_target(const struct lu_env *env, struct dt_device *key,
        if (unlikely(index >= ltds->ltd_tgts_bitmap->size))
                goto unlock;
 
-       ltd = LTD_TGT(ltds, index);
+       ltd = lfsck_ltd2tgt(ltds, index);
        if (unlikely(ltd == NULL))
                goto unlock;
 
@@ -3459,7 +3520,7 @@ void lfsck_del_target(const struct lu_env *env, struct dt_device *key,
 
        ltds->ltd_tgtnr--;
        cfs_bitmap_clear(ltds->ltd_tgts_bitmap, index);
-       LTD_TGT(ltds, index) = NULL;
+       lfsck_assign_tgt(ltds, NULL, index);
 
 unlock:
        if (ltd == NULL) {
@@ -3531,6 +3592,8 @@ static void __exit lfsck_exit(void)
 
 MODULE_AUTHOR("Intel Corporation <http://www.intel.com/>");
 MODULE_DESCRIPTION("LFSCK");
+MODULE_VERSION(LUSTRE_VERSION_STRING);
 MODULE_LICENSE("GPL");
 
-cfs_module(lfsck, LUSTRE_VERSION_STRING, lfsck_init, lfsck_exit);
+module_init(lfsck_init);
+module_exit(lfsck_exit);