Whamcloud - gitweb
LU-4423 lustre: don't declare extern variables in C files.
[fs/lustre-release.git] / lustre / lfsck / lfsck_layout.c
index 9f45c9a..2bd58b0 100644 (file)
@@ -270,7 +270,7 @@ static void lfsck_layout_assistant_sync_failures(const struct lu_env *env,
        int                                rc    = 0;
        ENTRY;
 
-       if (!lad->lad_incomplete)
+       if (!test_bit(LAD_INCOMPLETE, &lad->lad_flags))
                RETURN_EXIT;
 
        /* If the MDT has ever failed to verfiy some OST-objects,
@@ -368,7 +368,7 @@ static int lfsck_layout_verify_header_v1v3(struct dt_object *obj,
        }
 #endif
 
-       if (lov_pattern(pattern) != LOV_PATTERN_RAID0) {
+       if (!lov_pattern_supported_normal_comp(lov_pattern(pattern))) {
                CDEBUG(D_LFSCK, "Unsupported LOV EA pattern %u for the file "
                       DFID" in the component %x\n",
                       pattern, PFID(lfsck_dto2fid(obj)), comp_id);
@@ -379,8 +379,29 @@ static int lfsck_layout_verify_header_v1v3(struct dt_object *obj,
        return 0;
 }
 
+static int lfsck_layout_verify_header_foreign(struct dt_object *obj,
+                                             struct lov_foreign_md *lfm,
+                                             size_t len)
+{
+       /* magic has been verified already */
+       __u32 value_len = le32_to_cpu(lfm->lfm_length);
+       /* type and flags are not checked for instance */
+
+       CDEBUG(D_INFO, "foreign LOV EA, magic %x, len %u, type %x, flags %x, for file "DFID"\n",
+              le32_to_cpu(lfm->lfm_magic), value_len,
+              le32_to_cpu(lfm->lfm_type), le32_to_cpu(lfm->lfm_flags),
+              PFID(lfsck_dto2fid(obj)));
+
+       if (len != value_len + offsetof(typeof(*lfm), lfm_value))
+               CDEBUG(D_LFSCK, "foreign LOV EA internal size %u does not match EA full size %zu for file "DFID"\n",
+                      value_len, len, PFID(lfsck_dto2fid(obj)));
+
+       /* nothing to repair */
+       return -ENODATA;
+}
+
 static int lfsck_layout_verify_header(struct dt_object *obj,
-                                     struct lov_mds_md_v1 *lmm)
+                                     struct lov_mds_md_v1 *lmm, size_t len)
 {
        int rc = 0;
 
@@ -430,6 +451,10 @@ static int lfsck_layout_verify_header(struct dt_object *obj,
                                        le32_to_cpu(lcme->lcme_offset)), start,
                                        comp_id);
                }
+       } else if (le32_to_cpu(lmm->lmm_magic) == LOV_MAGIC_FOREIGN) {
+               rc = lfsck_layout_verify_header_foreign(obj,
+                                               (struct lov_foreign_md *)lmm,
+                                               len);
        } else {
                rc = lfsck_layout_verify_header_v1v3(obj, lmm, 1, 0);
        }
@@ -468,7 +493,7 @@ again:
                goto again;
        }
 
-       rc1 = lfsck_layout_verify_header(obj, buf->lb_buf);
+       rc1 = lfsck_layout_verify_header(obj, buf->lb_buf, rc);
 
        return rc1 ? rc1 : rc;
 }
@@ -622,7 +647,7 @@ lfsck_rbtree_insert(struct lfsck_layout_slave_data *llsd,
        return lrn;
 }
 
-extern const struct dt_index_operations lfsck_orphan_index_ops;
+static const struct dt_index_operations lfsck_orphan_index_ops;
 
 static int lfsck_rbtree_setup(const struct lu_env *env,
                              struct lfsck_component *com)
@@ -908,7 +933,7 @@ static int lfsck_layout_load_bitmap(const struct lu_env *env,
        }
 
        if (lo->ll_bitmap_size == 0) {
-               lad->lad_incomplete = 0;
+               clear_bit(LAD_INCOMPLETE, &lad->lad_flags);
                CFS_RESET_BITMAP(bitmap);
 
                RETURN(0);
@@ -920,9 +945,9 @@ static int lfsck_layout_load_bitmap(const struct lu_env *env,
                RETURN(rc >= 0 ? -EINVAL : rc);
 
        if (cfs_bitmap_check_empty(bitmap))
-               lad->lad_incomplete = 0;
+               clear_bit(LAD_INCOMPLETE, &lad->lad_flags);
        else
-               lad->lad_incomplete = 1;
+               set_bit(LAD_INCOMPLETE, &lad->lad_flags);
 
        RETURN(0);
 }
@@ -1106,7 +1131,7 @@ static int fid_is_for_ostobj(const struct lu_env *env,
        loa = &lfsck_env_info(env)->lti_loa;
        rc = dt_xattr_get(env, obj, lfsck_buf_get(env, loa, sizeof(*loa)),
                          XATTR_NAME_LMA);
-       if (rc >= sizeof(struct lustre_mdt_attrs)) {
+       if (rc >= (int)sizeof(struct lustre_mdt_attrs)) {
                lustre_lma_swab(&loa->loa_lma);
 
                return loa->loa_lma.lma_compat & LMAC_FID_ON_OST ? 1 : 0;
@@ -1467,7 +1492,7 @@ static int lfsck_layout_double_scan_result(const struct lu_env *env,
                        if (lfsck->li_master) {
                                struct lfsck_assistant_data *lad = com->lc_data;
 
-                               if (lad->lad_incomplete)
+                               if (test_bit(LAD_INCOMPLETE, &lad->lad_flags))
                                        lo->ll_status = LS_PARTIAL;
                                else
                                        lo->ll_status = LS_COMPLETED;
@@ -2881,7 +2906,7 @@ again:
        }
 
        lmm = buf->lb_buf;
-       rc1 = lfsck_layout_verify_header(parent, lmm);
+       rc1 = lfsck_layout_verify_header(parent, lmm, lovea_size);
 
        /* If the LOV EA crashed, the rebuild it. */
        if (rc1 == -EINVAL) {
@@ -3979,6 +4004,7 @@ static int lfsck_layout_repair_owner(const struct lu_env *env,
        struct dt_device                *dev    = lfsck_obj2dev(child);
        struct thandle                  *handle;
        int                              rc;
+       dt_obj_version_t                 version;
        ENTRY;
 
        tla->la_uid = pla->la_uid;
@@ -4001,14 +4027,18 @@ static int lfsck_layout_repair_owner(const struct lu_env *env,
        if (unlikely(lfsck_is_dead_obj(parent)))
                GOTO(unlock, rc = 1);
 
+       version = dt_version_get(env, child);
+       if (version == -EOPNOTSUPP)
+               version = 0;
+
        /* Get the latest parent's owner. */
        rc = dt_attr_get(env, parent, pla);
        if (rc != 0)
                GOTO(unlock, rc);
 
        /* Some others chown/chgrp during the LFSCK, needs to do nothing. */
-       if (unlikely(tla->la_uid != pla->la_uid ||
-                    tla->la_gid != pla->la_gid))
+       if (unlikely((!version && tla->la_ctime == 0) ||
+                    tla->la_uid != pla->la_uid || tla->la_gid != pla->la_gid))
                rc = 1;
        else
                rc = dt_attr_set(env, child, tla, handle);
@@ -4341,7 +4371,7 @@ out:
        if (rc < 0) {
                struct lfsck_assistant_data *lad = com->lc_data;
 
-               if (unlikely(lad->lad_exit)) {
+               if (unlikely(test_bit(LAD_EXIT, &lad->lad_flags))) {
                        rc = 0;
                } else if (rc == -ENOTCONN || rc == -ESHUTDOWN ||
                           rc == -ETIMEDOUT || rc == -EHOSTDOWN ||
@@ -4531,7 +4561,7 @@ static int lfsck_layout_assistant_handler_p2(const struct lu_env *env,
                        if (rc != 0 && bk->lb_param & LPF_FAILOUT)
                                RETURN(rc);
 
-                       if (unlikely(lad->lad_exit ||
+                       if (unlikely(test_bit(LAD_EXIT, &lad->lad_flags) ||
                                     !thread_is_running(&lfsck->li_thread)))
                                RETURN(0);
                        spin_lock(&ltds->ltd_lock);
@@ -4652,7 +4682,7 @@ static int lfsck_layout_async_query(const struct lu_env *env,
        *tmp = *lr;
        ptlrpc_request_set_replen(req);
 
-       llsaa = ptlrpc_req_async_args(req);
+       llsaa = ptlrpc_req_async_args(llsaa, req);
        llsaa->llsaa_exp = exp;
        llsaa->llsaa_com = lfsck_component_get(com);
        llsaa->llsaa_llst = llst;
@@ -5078,7 +5108,7 @@ static int lfsck_layout_reset(const struct lu_env *env,
        if (com->lc_lfsck->li_master) {
                struct lfsck_assistant_data *lad = com->lc_data;
 
-               lad->lad_incomplete = 0;
+               clear_bit(LAD_INCOMPLETE, &lad->lad_flags);
                CFS_RESET_BITMAP(lad->lad_bitmap);
        }
 
@@ -5326,7 +5356,7 @@ static int lfsck_layout_scan_stripes(const struct lu_env *env,
                                     struct dt_object *parent,
                                     struct lov_mds_md_v1 *lmm, __u32 comp_id)
 {
-       struct lfsck_thread_info        *info    = lfsck_env_info(env);
+       struct lfsck_thread_info        *info    = lfsck_env_info(env);
        struct lfsck_instance           *lfsck   = com->lc_lfsck;
        struct lfsck_bookmark           *bk      = &lfsck->li_bookmark_ram;
        struct lfsck_layout             *lo      = com->lc_file_ram;
@@ -5336,7 +5366,6 @@ static int lfsck_layout_scan_stripes(const struct lu_env *env,
        struct lfsck_tgt_descs          *ltds    = &lfsck->li_ost_descs;
        struct ptlrpc_thread            *mthread = &lfsck->li_thread;
        struct ptlrpc_thread            *athread = &lad->lad_thread;
-       struct l_wait_info               lwi     = { 0 };
        struct lu_buf                    buf;
        int                              rc      = 0;
        int                              i;
@@ -5366,11 +5395,10 @@ static int lfsck_layout_scan_stripes(const struct lu_env *env,
                if (unlikely(lovea_slot_is_dummy(objs)))
                        continue;
 
-               l_wait_event(mthread->t_ctl_waitq,
-                            lad->lad_prefetched < bk->lb_async_windows ||
-                            !thread_is_running(mthread) ||
-                            thread_is_stopped(athread),
-                            &lwi);
+               wait_event_idle(mthread->t_ctl_waitq,
+                               lad->lad_prefetched < bk->lb_async_windows ||
+                               !thread_is_running(mthread) ||
+                               thread_is_stopped(athread));
 
                if (unlikely(!thread_is_running(mthread)) ||
                             thread_is_stopped(athread))
@@ -5617,7 +5645,7 @@ fix:
                if (IS_ERR(handle))
                        GOTO(out, rc = PTR_ERR(handle));
 
-               lfsck_buf_init(&ea_buf, lmm, size);
+               lfsck_buf_init(&ea_buf, buf->lb_buf, size);
                rc = dt_declare_xattr_set(env, obj, &ea_buf, XATTR_NAME_LOV,
                                          LU_XATTR_REPLACE, handle);
                if (rc != 0)
@@ -7491,7 +7519,7 @@ static int lfsck_orphan_it_key_rec(const struct lu_env *env,
        return 0;
 }
 
-const struct dt_index_operations lfsck_orphan_index_ops = {
+static const struct dt_index_operations lfsck_orphan_index_ops = {
        .dio_lookup             = lfsck_orphan_index_lookup,
        .dio_declare_insert     = lfsck_orphan_index_declare_insert,
        .dio_insert             = lfsck_orphan_index_insert,