Whamcloud - gitweb
LU-8085 scrub: increase iteration cursor to skip unused inodes
[fs/lustre-release.git] / lustre / osd-ldiskfs / osd_scrub.c
index 5a035f8..0e497c3 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;
@@ -128,7 +128,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 +467,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 +549,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 +566,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 +596,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,7 +634,7 @@ 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))
@@ -1410,8 +1415,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 +1870,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 +1890,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;
 
@@ -2346,7 +2354,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 +2397,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 +2530,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 +2898,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;
 
@@ -3034,50 +3045,38 @@ static const char *scrub_param_names[] = {
        NULL
 };
 
-static int scrub_bits_dump(struct seq_file *m, int bits, const char *names[],
-                          const char *prefix)
+static void scrub_bits_dump(struct seq_file *m, int bits, const char *names[],
+                           const char *prefix)
 {
        int flag;
-       int rc;
        int i;
 
-       rc = seq_printf(m, "%s:%c", prefix, bits != 0 ? ' ' : '\n');
-       if (rc < 0)
-               return rc;
+       seq_printf(m, "%s:%c", prefix, bits != 0 ? ' ' : '\n');
 
        for (i = 0, flag = 1; bits != 0; i++, flag = 1 << i) {
                if (flag & bits) {
                        bits &= ~flag;
-                       rc = seq_printf(m, "%s%c", names[i],
-                                       bits != 0 ? ',' : '\n');
-                       if (rc < 0)
-                               return rc;
+                       seq_printf(m, "%s%c", names[i],
+                                  bits != 0 ? ',' : '\n');
                }
        }
-       return 0;
 }
 
-static int scrub_time_dump(struct seq_file *m, __u64 time, const char *prefix)
+static void scrub_time_dump(struct seq_file *m, __u64 time, const char *prefix)
 {
-       int rc;
-
        if (time != 0)
-               rc = seq_printf(m, "%s: "LPU64" seconds\n", prefix,
-                             cfs_time_current_sec() - time);
+               seq_printf(m, "%s: "LPU64" seconds\n", prefix,
+                          cfs_time_current_sec() - time);
        else
-               rc = seq_printf(m, "%s: N/A\n", prefix);
-       return rc;
+               seq_printf(m, "%s: N/A\n", prefix);
 }
 
-static int scrub_pos_dump(struct seq_file *m, __u64 pos, const char *prefix)
+static void scrub_pos_dump(struct seq_file *m, __u64 pos, const char *prefix)
 {
-       int rc;
-
        if (pos != 0)
-               rc = seq_printf(m, "%s: "LPU64"\n", prefix, pos);
+               seq_printf(m, "%s: "LPU64"\n", prefix, pos);
        else
-               rc = seq_printf(m, "%s: N/A\n", prefix);
-       return rc;
+               seq_printf(m, "%s: N/A\n", prefix);
 }
 
 int osd_scrub_dump(struct seq_file *m, struct osd_device *dev)
@@ -3086,71 +3085,48 @@ int osd_scrub_dump(struct seq_file *m, struct osd_device *dev)
        struct scrub_file *sf      = &scrub->os_file;
        __u64              checked;
        __u64              speed;
-       int                rc;
 
        down_read(&scrub->os_rwsem);
-       rc = seq_printf(m, "name: OI_scrub\n"
-                       "magic: 0x%x\n"
-                       "oi_files: %d\n"
-                       "status: %s\n",
-                       sf->sf_magic, (int)sf->sf_oi_count,
-                       scrub_status_names[sf->sf_status]);
-       if (rc < 0)
-               goto out;
+       seq_printf(m, "name: OI_scrub\n"
+                  "magic: 0x%x\n"
+                  "oi_files: %d\n"
+                  "status: %s\n",
+                  sf->sf_magic, (int)sf->sf_oi_count,
+                  scrub_status_names[sf->sf_status]);
 
-       rc = scrub_bits_dump(m, sf->sf_flags, scrub_flags_names,
-                            "flags");
-       if (rc < 0)
-               goto out;
+       scrub_bits_dump(m, sf->sf_flags, scrub_flags_names, "flags");
 
-       rc = scrub_bits_dump(m, sf->sf_param, scrub_param_names,
-                            "param");
-       if (rc < 0)
-               goto out;
+       scrub_bits_dump(m, sf->sf_param, scrub_param_names, "param");
 
-       rc = scrub_time_dump(m, sf->sf_time_last_complete,
-                            "time_since_last_completed");
-       if (rc < 0)
-               goto out;
+       scrub_time_dump(m, sf->sf_time_last_complete,
+                       "time_since_last_completed");
 
-       rc = scrub_time_dump(m, sf->sf_time_latest_start,
-                            "time_since_latest_start");
-       if (rc < 0)
-               goto out;
+       scrub_time_dump(m, sf->sf_time_latest_start,
+                       "time_since_latest_start");
 
-       rc = scrub_time_dump(m, sf->sf_time_last_checkpoint,
-                            "time_since_last_checkpoint");
-       if (rc < 0)
-               goto out;
+       scrub_time_dump(m, sf->sf_time_last_checkpoint,
+                       "time_since_last_checkpoint");
 
-       rc = scrub_pos_dump(m, sf->sf_pos_latest_start,
-                           "latest_start_position");
-       if (rc < 0)
-               goto out;
+       scrub_pos_dump(m, sf->sf_pos_latest_start,
+                       "latest_start_position");
 
-       rc = scrub_pos_dump(m, sf->sf_pos_last_checkpoint,
-                           "last_checkpoint_position");
-       if (rc < 0)
-               goto out;
+       scrub_pos_dump(m, sf->sf_pos_last_checkpoint,
+                       "last_checkpoint_position");
 
-       rc = scrub_pos_dump(m, sf->sf_pos_first_inconsistent,
-                           "first_failure_position");
-       if (rc < 0)
-               goto out;
+       scrub_pos_dump(m, sf->sf_pos_first_inconsistent,
+                       "first_failure_position");
 
        checked = sf->sf_items_checked + scrub->os_new_checked;
-       rc = seq_printf(m, "checked: "LPU64"\n"
-                     "updated: "LPU64"\n"
-                     "failed: "LPU64"\n"
-                     "prior_updated: "LPU64"\n"
-                     "noscrub: "LPU64"\n"
-                     "igif: "LPU64"\n"
-                     "success_count: %u\n",
-                     checked, sf->sf_items_updated, sf->sf_items_failed,
-                     sf->sf_items_updated_prior, sf->sf_items_noscrub,
-                     sf->sf_items_igif, sf->sf_success_count);
-       if (rc < 0)
-               goto out;
+       seq_printf(m, "checked: "LPU64"\n"
+                  "updated: "LPU64"\n"
+                  "failed: "LPU64"\n"
+                  "prior_updated: "LPU64"\n"
+                  "noscrub: "LPU64"\n"
+                  "igif: "LPU64"\n"
+                  "success_count: %u\n",
+                  checked, sf->sf_items_updated, sf->sf_items_failed,
+                  sf->sf_items_updated_prior, sf->sf_items_noscrub,
+                  sf->sf_items_igif, sf->sf_success_count);
 
        speed = checked;
        if (thread_is_running(&scrub->os_thread)) {
@@ -3165,31 +3141,30 @@ int osd_scrub_dump(struct seq_file *m, struct osd_device *dev)
                        do_div(new_checked, duration);
                if (rtime != 0)
                        do_div(speed, rtime);
-               rc = seq_printf(m, "run_time: %u seconds\n"
-                             "average_speed: "LPU64" objects/sec\n"
-                             "real-time_speed: "LPU64" objects/sec\n"
-                             "current_position: %u\n"
-                             "lf_scanned: "LPU64"\n"
-                             "lf_repaired: "LPU64"\n"
-                             "lf_failed: "LPU64"\n",
-                             rtime, speed, new_checked, scrub->os_pos_current,
-                             scrub->os_lf_scanned, scrub->os_lf_repaired,
-                             scrub->os_lf_failed);
+               seq_printf(m, "run_time: %u seconds\n"
+                          "average_speed: "LPU64" objects/sec\n"
+                          "real-time_speed: "LPU64" objects/sec\n"
+                          "current_position: %u\n"
+                          "lf_scanned: "LPU64"\n"
+                          "lf_repaired: "LPU64"\n"
+                          "lf_failed: "LPU64"\n",
+                          rtime, speed, new_checked, scrub->os_pos_current,
+                          scrub->os_lf_scanned, scrub->os_lf_repaired,
+                          scrub->os_lf_failed);
        } else {
                if (sf->sf_run_time != 0)
                        do_div(speed, sf->sf_run_time);
-               rc = seq_printf(m, "run_time: %u seconds\n"
-                             "average_speed: "LPU64" objects/sec\n"
-                             "real-time_speed: N/A\n"
-                             "current_position: N/A\n"
-                             "lf_scanned: "LPU64"\n"
-                             "lf_repaired: "LPU64"\n"
-                             "lf_failed: "LPU64"\n",
-                             sf->sf_run_time, speed, scrub->os_lf_scanned,
-                             scrub->os_lf_repaired, scrub->os_lf_failed);
+               seq_printf(m, "run_time: %u seconds\n"
+                          "average_speed: "LPU64" objects/sec\n"
+                          "real-time_speed: N/A\n"
+                          "current_position: N/A\n"
+                          "lf_scanned: "LPU64"\n"
+                          "lf_repaired: "LPU64"\n"
+                          "lf_failed: "LPU64"\n",
+                          sf->sf_run_time, speed, scrub->os_lf_scanned,
+                          scrub->os_lf_repaired, scrub->os_lf_failed);
        }
 
-out:
        up_read(&scrub->os_rwsem);
-       return (rc < 0 ? -ENOSPC : 0);
+       return 0;
 }