Whamcloud - gitweb
LU-7782 scrub: handle slave obj of striped directory
[fs/lustre-release.git] / lustre / osd-ldiskfs / osd_scrub.c
index 7236a21..257e18f 100644 (file)
@@ -98,7 +98,7 @@ static int osd_scrub_refresh_mapping(struct osd_thread_info *info,
                                     const struct lu_fid *fid,
                                     const struct osd_inode_id *id,
                                     int ops, bool force,
-                                    enum oi_check_flags flags)
+                                    enum oi_check_flags flags, bool *exist)
 {
        handle_t *th;
        int       rc;
@@ -115,7 +115,8 @@ static int osd_scrub_refresh_mapping(struct osd_thread_info *info,
                rc = PTR_ERR(th);
                CDEBUG(D_LFSCK, "%s: fail to start trans for scrub op %d "
                       DFID" => %u/%u: rc = %d\n", osd_name(dev), ops,
-                      PFID(fid), id->oii_ino, id->oii_gen, rc);
+                      PFID(fid), id ? id->oii_ino : -1, id ? id->oii_gen : -1,
+                      rc);
                RETURN(rc);
        }
 
@@ -128,7 +129,7 @@ static int osd_scrub_refresh_mapping(struct osd_thread_info *info,
                }
                break;
        case DTO_INDEX_INSERT:
-               rc = osd_oi_insert(info, dev, fid, id, th, flags);
+               rc = osd_oi_insert(info, dev, fid, id, th, flags, exist);
                if (unlikely(rc == -EEXIST)) {
                        rc = 1;
                        /* XXX: There are trouble things when adding OI
@@ -467,9 +468,9 @@ osd_scrub_check_update(struct osd_thread_info *info, struct osd_device *dev,
        struct osd_inconsistent_item *oii    = NULL;
        struct inode                 *inode  = NULL;
        int                           ops    = DTO_INDEX_UPDATE;
-       int                           idx;
        int                           rc;
        bool                          converted = false;
+       bool                          exist     = false;
        ENTRY;
 
        down_write(&scrub->os_rwsem);
@@ -549,7 +550,6 @@ iget:
                if (!scrub->os_partial_scan)
                        scrub->os_full_speed = 1;
 
-               idx = osd_oi_fid2idx(dev, fid);
                switch (val) {
                case SCRUB_NEXT_NOLMA:
                        sf->sf_flags |= SF_UPGRADE;
@@ -567,9 +567,6 @@ iget:
                case SCRUB_NEXT_OSTOBJ_OLD:
                        break;
                default:
-                       sf->sf_flags |= SF_RECREATED;
-                       if (unlikely(!ldiskfs_test_bit(idx, sf->sf_oi_bitmap)))
-                               ldiskfs_set_bit(idx, sf->sf_oi_bitmap);
                        break;
                }
        } else if (osd_id_eq(lid, lid2)) {
@@ -600,12 +597,21 @@ iget:
 
        rc = osd_scrub_refresh_mapping(info, dev, fid, lid, ops, false,
                        (val == SCRUB_NEXT_OSTOBJ ||
-                        val == SCRUB_NEXT_OSTOBJ_OLD) ? OI_KNOWN_ON_OST : 0);
+                        val == SCRUB_NEXT_OSTOBJ_OLD) ? OI_KNOWN_ON_OST : 0,
+                       &exist);
        if (rc == 0) {
                if (scrub->os_in_prior)
                        sf->sf_items_updated_prior++;
                else
                        sf->sf_items_updated++;
+
+               if (ops == DTO_INDEX_INSERT && val == 0 && !exist) {
+                       int idx = osd_oi_fid2idx(dev, fid);
+
+                       sf->sf_flags |= SF_RECREATED;
+                       if (unlikely(!ldiskfs_test_bit(idx, sf->sf_oi_bitmap)))
+                               ldiskfs_set_bit(idx, sf->sf_oi_bitmap);
+               }
        }
 
        GOTO(out, rc);
@@ -629,14 +635,17 @@ out:
                                DTO_INDEX_DELETE, false,
                                (val == SCRUB_NEXT_OSTOBJ ||
                                 val == SCRUB_NEXT_OSTOBJ_OLD) ?
-                               OI_KNOWN_ON_OST : 0);
+                               OI_KNOWN_ON_OST : 0, NULL);
        up_write(&scrub->os_rwsem);
 
        if (inode != NULL && !IS_ERR(inode))
                iput(inode);
 
        if (oii != NULL) {
-               LASSERT(list_empty(&oii->oii_list));
+               spin_lock(&scrub->os_lock);
+               if (likely(!list_empty(&oii->oii_list)))
+                       list_del(&oii->oii_list);
+               spin_unlock(&scrub->os_lock);
 
                OBD_FREE_PTR(oii);
        }
@@ -1027,7 +1036,6 @@ static int osd_scrub_next(struct osd_thread_info *info, struct osd_device *dev,
 
                        oii = list_entry(scrub->os_inconsistent_items.next,
                                struct osd_inconsistent_item, oii_list);
-                       list_del_init(&oii->oii_list);
                        spin_unlock(&scrub->os_lock);
 
                        *oic = &oii->oii_cache;
@@ -1218,16 +1226,16 @@ static void osd_scrub_join(struct osd_device *dev, __u32 flags,
                sf->sf_status = SS_SCANNING;
        }
 
-       if (flags & SS_AUTO_FULL) {
-               sf->sf_flags |= SF_AUTO;
-               scrub->os_full_speed = 1;
-       }
-
        if (sf->sf_flags & (SF_RECREATED | SF_INCONSISTENT | SF_UPGRADE))
                scrub->os_full_speed = 1;
        else
                scrub->os_full_speed = 0;
 
+       if (flags & SS_AUTO_FULL) {
+               sf->sf_flags |= SF_AUTO;
+               scrub->os_full_speed = 1;
+       }
+
        scrub->os_new_checked = 0;
        if (sf->sf_pos_last_checkpoint != 0)
                sf->sf_pos_latest_start = sf->sf_pos_last_checkpoint + 1;
@@ -1410,8 +1418,11 @@ full:
                       *count < max) {
                        if (param.offset +
                                ldiskfs_itable_unused_count(param.sb, desc) >
-                           LDISKFS_INODES_PER_GROUP(param.sb))
+                           LDISKFS_INODES_PER_GROUP(param.sb)) {
+                               *pos = 1 + (param.bg + 1) *
+                                       LDISKFS_INODES_PER_GROUP(param.sb);
                                goto next_group;
+                       }
 
                        rc = next(info, dev, &param, &oic, noslot);
                        switch (rc) {
@@ -1862,7 +1873,7 @@ osd_ios_scan_one(struct osd_thread_info *info, struct osd_device *dev,
                        RETURN(rc);
 
                rc = osd_scrub_refresh_mapping(info, dev, &tfid, id,
-                                              DTO_INDEX_INSERT, true, 0);
+                                              DTO_INDEX_INSERT, true, 0, NULL);
                if (rc > 0)
                        rc = 0;
 
@@ -1882,7 +1893,7 @@ osd_ios_scan_one(struct osd_thread_info *info, struct osd_device *dev,
        }
 
        rc = osd_scrub_refresh_mapping(info, dev, &tfid, id,
-                                      DTO_INDEX_UPDATE, true, 0);
+                                      DTO_INDEX_UPDATE, true, 0, NULL);
        if (rc > 0)
                rc = 0;
 
@@ -1894,11 +1905,11 @@ osd_ios_scan_one(struct osd_thread_info *info, struct osd_device *dev,
  * or filter_fid_old), move them back to its proper /O/<seq>/d<x>.
  */
 #ifdef HAVE_FILLDIR_USE_CTX
-static int osd_ios_lf_fill(struct dir_context *buf, const char *name,
-                          int namelen,
+static int osd_ios_lf_fill(struct dir_context *buf,
 #else
-static int osd_ios_lf_fill(void *buf, const char *name, int namelen,
+static int osd_ios_lf_fill(void *buf,
 #endif
+                          const char *name, int namelen,
                           loff_t offset, __u64 ino, unsigned d_type)
 {
        struct osd_ios_filldir_buf *fill_buf =
@@ -1968,11 +1979,11 @@ put:
 }
 
 #ifdef HAVE_FILLDIR_USE_CTX
-static int osd_ios_varfid_fill(struct dir_context  *buf, const char *name,
-                              int namelen,
+static int osd_ios_varfid_fill(struct dir_context *buf,
 #else
-static int osd_ios_varfid_fill(void *buf, const char *name, int namelen,
+static int osd_ios_varfid_fill(void *buf,
 #endif
+                              const char *name, int namelen,
                               loff_t offset, __u64 ino, unsigned d_type)
 {
        struct osd_ios_filldir_buf *fill_buf =
@@ -2001,11 +2012,11 @@ static int osd_ios_varfid_fill(void *buf, const char *name, int namelen,
 }
 
 #ifdef HAVE_FILLDIR_USE_CTX
-static int osd_ios_dl_fill(struct dir_context  *buf, const char *name,
-                          int namelen,
+static int osd_ios_dl_fill(struct dir_context *buf,
 #else
-static int osd_ios_dl_fill(void *buf, const char *name, int namelen,
+static int osd_ios_dl_fill(void *buf,
 #endif
+                          const char *name, int namelen,
                           loff_t offset, __u64 ino, unsigned d_type)
 {
        struct osd_ios_filldir_buf *fill_buf =
@@ -2043,11 +2054,11 @@ static int osd_ios_dl_fill(void *buf, const char *name, int namelen,
 }
 
 #ifdef HAVE_FILLDIR_USE_CTX
-static int osd_ios_uld_fill(struct dir_context *buf, const char *name,
-                           int namelen,
+static int osd_ios_uld_fill(struct dir_context *buf,
 #else
-static int osd_ios_uld_fill(void *buf, const char *name, int namelen,
+static int osd_ios_uld_fill(void *buf,
 #endif
+                           const char *name, int namelen,
                            loff_t offset, __u64 ino, unsigned d_type)
 {
        struct osd_ios_filldir_buf *fill_buf =
@@ -2078,11 +2089,11 @@ static int osd_ios_uld_fill(void *buf, const char *name, int namelen,
 }
 
 #ifdef HAVE_FILLDIR_USE_CTX
-static int osd_ios_root_fill(struct dir_context *buf, const char *name,
-                            int namelen,
+static int osd_ios_root_fill(struct dir_context *buf,
 #else
-static int osd_ios_root_fill(void *buf, const char *name, int namelen,
+static int osd_ios_root_fill(void *buf,
 #endif
+                            const char *name, int namelen,
                             loff_t offset, __u64 ino, unsigned d_type)
 {
        struct osd_ios_filldir_buf *fill_buf =
@@ -2346,7 +2357,7 @@ static int osd_initial_OI_scrub(struct osd_thread_info *info,
                else if (PTR_ERR(child) == -ENOENT)
                        osd_scrub_refresh_mapping(info, dev, &map->olm_fid,
                                                  NULL, DTO_INDEX_DELETE,
-                                                 true, 0);
+                                                 true, 0, NULL);
                map++;
        }
 
@@ -2389,8 +2400,9 @@ static int do_osd_scrub_start(struct osd_device *dev, __u32 flags)
 again:
        if (thread_is_running(thread)) {
                spin_unlock(&scrub->os_lock);
-               if (!(scrub->os_file.sf_flags & SF_AUTO) ||
-                    (flags & (SS_AUTO_FULL | SS_AUTO_PARTIAL)))
+               if (!(scrub->os_file.sf_flags & SF_AUTO ||
+                     scrub->os_partial_scan) ||
+                    (flags & SS_AUTO_PARTIAL))
                        RETURN(-EALREADY);
 
                osd_scrub_join(dev, flags, false);
@@ -2521,7 +2533,7 @@ int osd_scrub_setup(const struct lu_env *env, struct osd_device *dev)
                RETURN(PTR_ERR(filp));
        }
 
-       inode = filp->f_path.dentry->d_inode;
+       inode = file_inode(filp);
        /* 'What the @fid is' is not imporatant, because the object
         * has no OI mapping, and only is visible inside the OSD.*/
        lu_igif_build(fid, inode->i_ino, inode->i_generation);
@@ -2889,6 +2901,8 @@ static int osd_otable_it_load(const struct lu_env *env,
        if (it->ooi_user_ready)
                RETURN(-EPERM);
 
+       LASSERT(!scrub->os_partial_scan);
+
        if (hash > OSD_OTABLE_MAX_HASH)
                hash = OSD_OTABLE_MAX_HASH;