4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License version 2 for more details. A copy is
14 * included in the COPYING file that accompanied this code.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * Copyright (c) 2012, 2013, Intel Corporation.
26 * lustre/osd-ldiskfs/osd_scrub.c
28 * Top-level entry points into osd module
30 * The OI scrub is used for rebuilding Object Index files when restores MDT from
33 * The otable based iterator scans ldiskfs inode table to feed up layer LFSCK.
35 * Author: Fan Yong <yong.fan@whamcloud.com>
38 #define DEBUG_SUBSYSTEM S_MDS
40 #include <lustre/lustre_idl.h>
41 #include <lustre_disk.h>
42 #include <dt_object.h>
44 #include "osd_internal.h"
46 #include "osd_scrub.h"
48 #define HALF_SEC (CFS_HZ >> 1)
50 #define OSD_OTABLE_MAX_HASH 0x00000000ffffffffULL
52 #define SCRUB_NEXT_BREAK 1 /* exit current loop and process next group */
53 #define SCRUB_NEXT_CONTINUE 2 /* skip current object and process next bit */
54 #define SCRUB_NEXT_EXIT 3 /* exit all the loops */
55 #define SCRUB_NEXT_WAIT 4 /* wait for free cache slot */
56 #define SCRUB_NEXT_CRASH 5 /* simulate system crash during OI scrub */
57 #define SCRUB_NEXT_FATAL 6 /* simulate failure during OI scrub */
58 #define SCRUB_NEXT_NOSCRUB 7 /* new created object, no scrub on it */
59 #define SCRUB_NEXT_NOLMA 8 /* the inode has no FID-in-LMA */
60 #define SCRUB_NEXT_OSTOBJ 9 /* for OST-object */
61 #define SCRUB_NEXT_OSTOBJ_OLD 10 /* old OST-object, no LMA or no FID-on-OST
66 static inline struct osd_device *osd_scrub2dev(struct osd_scrub *scrub)
68 return container_of0(scrub, struct osd_device, od_scrub);
71 static inline struct super_block *osd_scrub2sb(struct osd_scrub *scrub)
73 return osd_sb(osd_scrub2dev(scrub));
76 static inline int osd_scrub_has_window(struct osd_scrub *scrub,
77 struct osd_otable_cache *ooc)
79 return scrub->os_pos_current < ooc->ooc_pos_preload + SCRUB_WINDOW_SIZE;
83 * update/insert/delete the specified OI mapping (@fid @id) according to the ops
85 * \retval 1, changed nothing
86 * \retval 0, changed successfully
87 * \retval -ve, on error
89 static int osd_scrub_refresh_mapping(struct osd_thread_info *info,
90 struct osd_device *dev,
91 const struct lu_fid *fid,
92 const struct osd_inode_id *id,
93 int ops, enum oi_check_flags flags)
95 const struct lu_env *env = info->oti_env;
97 struct osd_thandle *oh;
101 th = dt_trans_create(env, &dev->od_dt_dev);
105 oh = container_of0(th, struct osd_thandle, ot_super);
106 LASSERT(oh->ot_handle == NULL);
109 case DTO_INDEX_UPDATE:
110 osd_trans_declare_op(env, oh, OSD_OT_UPDATE,
111 osd_dto_credits_noquota[DTO_INDEX_UPDATE]);
112 rc = dt_trans_start_local(env, &dev->od_dt_dev, th);
116 rc = osd_oi_update(info, dev, fid, id, th, flags);
117 if (unlikely(rc == -ENOENT)) {
118 /* Some unlink thread may removed the OI mapping. */
122 case DTO_INDEX_INSERT:
123 osd_trans_declare_op(env, oh, OSD_OT_INSERT,
124 osd_dto_credits_noquota[DTO_INDEX_INSERT]);
125 rc = dt_trans_start_local(env, &dev->od_dt_dev, th);
129 rc = osd_oi_insert(info, dev, fid, id, th, flags);
130 if (unlikely(rc == -EEXIST)) {
132 /* XXX: There are trouble things when adding OI
133 * mapping for IGIF object, which may cause
134 * multiple objects to be mapped to the same
135 * IGIF formatted FID. Consider the following
138 * 1) The MDT is upgrading from 1.8 device.
139 * The OI scrub generates IGIF FID1 for the
140 * OBJ1 and adds the OI mapping.
142 * 2) For some reason, the OI scrub does not
143 * process all the IGIF objects completely.
145 * 3) The MDT is backuped and restored against
148 * 4) When the MDT mounts up, the OI scrub will
149 * try to rebuild the OI files. For some IGIF
150 * object, OBJ2, which was not processed by the
151 * OI scrub before the backup/restore, and the
152 * new generated IGIF formatted FID may be just
153 * the FID1, the same as OBJ1.
155 * Under such case, the OI scrub cannot know how
156 * to generate new FID for the OBJ2.
158 * Currently, we do nothing for that. One possible
159 * solution is to generate new normal FID for the
162 * Anyway, it is rare, only exists in theory. */
165 case DTO_INDEX_DELETE:
166 osd_trans_declare_op(env, oh, OSD_OT_DELETE,
167 osd_dto_credits_noquota[DTO_INDEX_DELETE]);
168 rc = dt_trans_start_local(env, &dev->od_dt_dev, th);
172 rc = osd_oi_delete(info, dev, fid, th, flags);
174 /* It is normal that the unlink thread has removed the
175 * OI mapping already. */
180 LASSERTF(0, "Unexpected ops %d\n", ops);
187 dt_trans_stop(env, &dev->od_dt_dev, th);
191 /* OI_scrub file ops */
193 static void osd_scrub_file_to_cpu(struct scrub_file *des,
194 struct scrub_file *src)
196 memcpy(des->sf_uuid, src->sf_uuid, 16);
197 des->sf_flags = le64_to_cpu(src->sf_flags);
198 des->sf_magic = le32_to_cpu(src->sf_magic);
199 des->sf_status = le16_to_cpu(src->sf_status);
200 des->sf_param = le16_to_cpu(src->sf_param);
201 des->sf_time_last_complete =
202 le64_to_cpu(src->sf_time_last_complete);
203 des->sf_time_latest_start =
204 le64_to_cpu(src->sf_time_latest_start);
205 des->sf_time_last_checkpoint =
206 le64_to_cpu(src->sf_time_last_checkpoint);
207 des->sf_pos_latest_start =
208 le64_to_cpu(src->sf_pos_latest_start);
209 des->sf_pos_last_checkpoint =
210 le64_to_cpu(src->sf_pos_last_checkpoint);
211 des->sf_pos_first_inconsistent =
212 le64_to_cpu(src->sf_pos_first_inconsistent);
213 des->sf_items_checked =
214 le64_to_cpu(src->sf_items_checked);
215 des->sf_items_updated =
216 le64_to_cpu(src->sf_items_updated);
217 des->sf_items_failed =
218 le64_to_cpu(src->sf_items_failed);
219 des->sf_items_updated_prior =
220 le64_to_cpu(src->sf_items_updated_prior);
221 des->sf_run_time = le32_to_cpu(src->sf_run_time);
222 des->sf_success_count = le32_to_cpu(src->sf_success_count);
223 des->sf_oi_count = le16_to_cpu(src->sf_oi_count);
224 memcpy(des->sf_oi_bitmap, src->sf_oi_bitmap, SCRUB_OI_BITMAP_SIZE);
227 static void osd_scrub_file_to_le(struct scrub_file *des,
228 struct scrub_file *src)
230 memcpy(des->sf_uuid, src->sf_uuid, 16);
231 des->sf_flags = cpu_to_le64(src->sf_flags);
232 des->sf_magic = cpu_to_le32(src->sf_magic);
233 des->sf_status = cpu_to_le16(src->sf_status);
234 des->sf_param = cpu_to_le16(src->sf_param);
235 des->sf_time_last_complete =
236 cpu_to_le64(src->sf_time_last_complete);
237 des->sf_time_latest_start =
238 cpu_to_le64(src->sf_time_latest_start);
239 des->sf_time_last_checkpoint =
240 cpu_to_le64(src->sf_time_last_checkpoint);
241 des->sf_pos_latest_start =
242 cpu_to_le64(src->sf_pos_latest_start);
243 des->sf_pos_last_checkpoint =
244 cpu_to_le64(src->sf_pos_last_checkpoint);
245 des->sf_pos_first_inconsistent =
246 cpu_to_le64(src->sf_pos_first_inconsistent);
247 des->sf_items_checked =
248 cpu_to_le64(src->sf_items_checked);
249 des->sf_items_updated =
250 cpu_to_le64(src->sf_items_updated);
251 des->sf_items_failed =
252 cpu_to_le64(src->sf_items_failed);
253 des->sf_items_updated_prior =
254 cpu_to_le64(src->sf_items_updated_prior);
255 des->sf_run_time = cpu_to_le32(src->sf_run_time);
256 des->sf_success_count = cpu_to_le32(src->sf_success_count);
257 des->sf_oi_count = cpu_to_le16(src->sf_oi_count);
258 memcpy(des->sf_oi_bitmap, src->sf_oi_bitmap, SCRUB_OI_BITMAP_SIZE);
261 static void osd_scrub_file_init(struct osd_scrub *scrub, __u8 *uuid)
263 struct scrub_file *sf = &scrub->os_file;
265 memset(sf, 0, sizeof(*sf));
266 memcpy(sf->sf_uuid, uuid, 16);
267 sf->sf_magic = SCRUB_MAGIC_V1;
268 sf->sf_status = SS_INIT;
271 void osd_scrub_file_reset(struct osd_scrub *scrub, __u8 *uuid, __u64 flags)
273 struct scrub_file *sf = &scrub->os_file;
275 CDEBUG(D_LFSCK, "Reset OI scrub file, flags = "LPX64"\n", flags);
276 memcpy(sf->sf_uuid, uuid, 16);
277 sf->sf_status = SS_INIT;
278 sf->sf_flags |= flags;
281 sf->sf_time_latest_start = 0;
282 sf->sf_time_last_checkpoint = 0;
283 sf->sf_pos_latest_start = 0;
284 sf->sf_pos_last_checkpoint = 0;
285 sf->sf_pos_first_inconsistent = 0;
286 sf->sf_items_checked = 0;
287 sf->sf_items_updated = 0;
288 sf->sf_items_failed = 0;
289 sf->sf_items_updated_prior = 0;
290 sf->sf_items_noscrub = 0;
291 sf->sf_items_igif = 0;
294 static int osd_scrub_file_load(struct osd_scrub *scrub)
297 char *name = LDISKFS_SB(osd_scrub2sb(scrub))->s_es->s_volume_name;
298 int len = sizeof(scrub->os_file_disk);
301 rc = osd_ldiskfs_read(scrub->os_inode, &scrub->os_file_disk, len, &pos);
303 struct scrub_file *sf = &scrub->os_file;
305 osd_scrub_file_to_cpu(sf, &scrub->os_file_disk);
306 if (sf->sf_magic != SCRUB_MAGIC_V1) {
307 CWARN("%.16s: invalid scrub magic 0x%x != 0x%x\n,",
308 name, sf->sf_magic, SCRUB_MAGIC_V1);
309 /* Process it as new scrub file. */
314 } else if (rc != 0) {
315 CERROR("%.16s: fail to load scrub file, expected = %d, "
316 "rc = %d\n", name, len, rc);
320 /* return -ENOENT for empty scrub file case. */
327 int osd_scrub_file_store(struct osd_scrub *scrub)
329 struct osd_device *dev;
332 int len = sizeof(scrub->os_file_disk);
336 dev = container_of0(scrub, struct osd_device, od_scrub);
337 credits = osd_dto_credits_noquota[DTO_WRITE_BASE] +
338 osd_dto_credits_noquota[DTO_WRITE_BLOCK];
339 jh = ldiskfs_journal_start_sb(osd_sb(dev), credits);
342 CERROR("%.16s: fail to start trans for scrub store, rc = %d\n",
343 LDISKFS_SB(osd_scrub2sb(scrub))->s_es->s_volume_name,rc);
347 osd_scrub_file_to_le(&scrub->os_file_disk, &scrub->os_file);
348 rc = osd_ldiskfs_write_record(scrub->os_inode, &scrub->os_file_disk,
350 ldiskfs_journal_stop(jh);
352 CERROR("%.16s: fail to store scrub file, expected = %d, "
354 LDISKFS_SB(osd_scrub2sb(scrub))->s_es->s_volume_name,
356 scrub->os_time_last_checkpoint = cfs_time_current();
357 scrub->os_time_next_checkpoint = scrub->os_time_last_checkpoint +
358 cfs_time_seconds(SCRUB_CHECKPOINT_INTERVAL);
364 static int osd_scrub_prep(struct osd_device *dev)
366 struct osd_scrub *scrub = &dev->od_scrub;
367 struct ptlrpc_thread *thread = &scrub->os_thread;
368 struct scrub_file *sf = &scrub->os_file;
369 __u32 flags = scrub->os_start_flags;
373 down_write(&scrub->os_rwsem);
374 if (flags & SS_SET_FAILOUT)
375 sf->sf_param |= SP_FAILOUT;
377 if (flags & SS_CLEAR_FAILOUT)
378 sf->sf_param &= ~SP_FAILOUT;
380 if (flags & SS_RESET)
381 osd_scrub_file_reset(scrub,
382 LDISKFS_SB(osd_sb(dev))->s_es->s_uuid, 0);
384 if (flags & SS_AUTO) {
385 scrub->os_full_speed = 1;
386 sf->sf_flags |= SF_AUTO;
388 scrub->os_full_speed = 0;
391 if (sf->sf_flags & (SF_RECREATED | SF_INCONSISTENT | SF_UPGRADE))
392 scrub->os_full_speed = 1;
394 scrub->os_in_prior = 0;
395 scrub->os_waiting = 0;
396 scrub->os_paused = 0;
397 scrub->os_new_checked = 0;
398 if (sf->sf_pos_last_checkpoint != 0)
399 sf->sf_pos_latest_start = sf->sf_pos_last_checkpoint + 1;
401 sf->sf_pos_latest_start = LDISKFS_FIRST_INO(osd_sb(dev)) + 1;
403 scrub->os_pos_current = sf->sf_pos_latest_start;
404 sf->sf_status = SS_SCANNING;
405 sf->sf_time_latest_start = cfs_time_current_sec();
406 sf->sf_time_last_checkpoint = sf->sf_time_latest_start;
407 rc = osd_scrub_file_store(scrub);
409 spin_lock(&scrub->os_lock);
410 thread_set_flags(thread, SVC_RUNNING);
411 spin_unlock(&scrub->os_lock);
412 cfs_waitq_broadcast(&thread->t_ctl_waitq);
414 up_write(&scrub->os_rwsem);
420 osd_scrub_check_update(struct osd_thread_info *info, struct osd_device *dev,
421 struct osd_idmap_cache *oic, int val)
423 struct osd_scrub *scrub = &dev->od_scrub;
424 struct scrub_file *sf = &scrub->os_file;
425 struct lu_fid *fid = &oic->oic_fid;
426 struct osd_inode_id *lid = &oic->oic_lid;
427 struct osd_inode_id *lid2 = &info->oti_id;
428 struct osd_inconsistent_item *oii = NULL;
429 struct inode *inode = NULL;
430 int ops = DTO_INDEX_UPDATE;
435 down_write(&scrub->os_rwsem);
436 scrub->os_new_checked++;
440 if (scrub->os_in_prior)
441 oii = cfs_list_entry(oic, struct osd_inconsistent_item,
444 if (lid->oii_ino < sf->sf_pos_latest_start && oii == NULL)
447 if (fid_is_igif(fid))
450 if (val == SCRUB_NEXT_OSTOBJ_OLD) {
451 inode = osd_iget(info, dev, lid);
454 /* Someone removed the inode. */
455 if (rc == -ENOENT || rc == -ESTALE)
460 sf->sf_flags |= SF_UPGRADE;
461 rc = osd_ea_fid_set(info, inode, fid,
467 if ((val == SCRUB_NEXT_NOLMA) &&
468 (!dev->od_handle_nolma || OBD_FAIL_CHECK(OBD_FAIL_FID_NOLMA)))
471 if ((oii != NULL && oii->oii_insert) || (val == SCRUB_NEXT_NOLMA))
474 rc = osd_oi_lookup(info, dev, fid, lid2,
475 (val == SCRUB_NEXT_OSTOBJ ||
476 val == SCRUB_NEXT_OSTOBJ_OLD) ? OI_KNOWN_ON_OST : 0);
483 inode = osd_iget(info, dev, lid);
486 /* Someone removed the inode. */
487 if (rc == -ENOENT || rc == -ESTALE)
493 scrub->os_full_speed = 1;
494 ops = DTO_INDEX_INSERT;
495 idx = osd_oi_fid2idx(dev, fid);
497 case SCRUB_NEXT_NOLMA:
498 sf->sf_flags |= SF_UPGRADE;
499 rc = osd_ea_fid_set(info, inode, fid, 0, 0);
503 if (!(sf->sf_flags & SF_INCONSISTENT))
504 dev->od_igif_inoi = 0;
506 case SCRUB_NEXT_OSTOBJ:
507 sf->sf_flags |= SF_INCONSISTENT;
508 case SCRUB_NEXT_OSTOBJ_OLD:
511 sf->sf_flags |= SF_RECREATED;
512 if (unlikely(!ldiskfs_test_bit(idx, sf->sf_oi_bitmap)))
513 ldiskfs_set_bit(idx, sf->sf_oi_bitmap);
516 } else if (osd_id_eq(lid, lid2)) {
519 scrub->os_full_speed = 1;
520 sf->sf_flags |= SF_INCONSISTENT;
522 /* XXX: If the device is restored from file-level backup, then
523 * some IGIFs may have been already in OI files, and some
524 * may be not yet. Means upgrading from 1.8 may be partly
525 * processed, but some clients may hold some immobilized
526 * IGIFs, and use them to access related objects. Under
527 * such case, OSD does not know whether an given IGIF has
528 * been processed or to be processed, and it also cannot
529 * generate local ino#/gen# directly from the immobilized
530 * IGIF because of the backup/restore. Then force OSD to
531 * lookup the given IGIF in OI files, and if no entry,
532 * then ask the client to retry after upgrading completed.
533 * No better choice. */
534 dev->od_igif_inoi = 1;
537 rc = osd_scrub_refresh_mapping(info, dev, fid, lid, ops,
538 (val == SCRUB_NEXT_OSTOBJ ||
539 val == SCRUB_NEXT_OSTOBJ_OLD) ? OI_KNOWN_ON_OST : 0);
541 if (scrub->os_in_prior)
542 sf->sf_items_updated_prior++;
544 sf->sf_items_updated++;
546 /* The target has been changed, need to be re-loaded. */
547 lu_object_purge(info->oti_env, osd2lu_dev(dev), fid);
554 sf->sf_items_failed++;
555 if (sf->sf_pos_first_inconsistent == 0 ||
556 sf->sf_pos_first_inconsistent > lid->oii_ino)
557 sf->sf_pos_first_inconsistent = lid->oii_ino;
562 /* There may be conflict unlink during the OI scrub,
563 * if happend, then remove the new added OI mapping. */
564 if (ops == DTO_INDEX_INSERT && inode != NULL && !IS_ERR(inode) &&
565 unlikely(inode->i_nlink == 0))
566 osd_scrub_refresh_mapping(info, dev, fid, lid,
568 (val == SCRUB_NEXT_OSTOBJ ||
569 val == SCRUB_NEXT_OSTOBJ_OLD) ?
570 OI_KNOWN_ON_OST : 0);
571 up_write(&scrub->os_rwsem);
573 if (inode != NULL && !IS_ERR(inode))
577 LASSERT(!cfs_list_empty(&oii->oii_list));
579 spin_lock(&scrub->os_lock);
580 cfs_list_del_init(&oii->oii_list);
581 spin_unlock(&scrub->os_lock);
584 RETURN(sf->sf_param & SP_FAILOUT ? rc : 0);
587 static int osd_scrub_checkpoint(struct osd_scrub *scrub)
589 struct scrub_file *sf = &scrub->os_file;
592 if (likely(cfs_time_before(cfs_time_current(),
593 scrub->os_time_next_checkpoint) ||
594 scrub->os_new_checked == 0))
597 down_write(&scrub->os_rwsem);
598 sf->sf_items_checked += scrub->os_new_checked;
599 scrub->os_new_checked = 0;
600 sf->sf_pos_last_checkpoint = scrub->os_pos_current;
601 sf->sf_time_last_checkpoint = cfs_time_current_sec();
602 sf->sf_run_time += cfs_duration_sec(cfs_time_current() + HALF_SEC -
603 scrub->os_time_last_checkpoint);
604 rc = osd_scrub_file_store(scrub);
605 up_write(&scrub->os_rwsem);
610 static void osd_scrub_post(struct osd_scrub *scrub, int result)
612 struct scrub_file *sf = &scrub->os_file;
615 down_write(&scrub->os_rwsem);
616 spin_lock(&scrub->os_lock);
617 thread_set_flags(&scrub->os_thread, SVC_STOPPING);
618 spin_unlock(&scrub->os_lock);
619 if (scrub->os_new_checked > 0) {
620 sf->sf_items_checked += scrub->os_new_checked;
621 scrub->os_new_checked = 0;
622 sf->sf_pos_last_checkpoint = scrub->os_pos_current;
624 sf->sf_time_last_checkpoint = cfs_time_current_sec();
626 struct osd_device *dev =
627 container_of0(scrub, struct osd_device, od_scrub);
629 dev->od_igif_inoi = 1;
630 sf->sf_status = SS_COMPLETED;
631 memset(sf->sf_oi_bitmap, 0, SCRUB_OI_BITMAP_SIZE);
632 sf->sf_flags &= ~(SF_RECREATED | SF_INCONSISTENT |
633 SF_UPGRADE | SF_AUTO);
634 sf->sf_time_last_complete = sf->sf_time_last_checkpoint;
635 sf->sf_success_count++;
636 } else if (result == 0) {
637 if (scrub->os_paused)
638 sf->sf_status = SS_PAUSED;
640 sf->sf_status = SS_STOPPED;
642 sf->sf_status = SS_FAILED;
644 sf->sf_run_time += cfs_duration_sec(cfs_time_current() + HALF_SEC -
645 scrub->os_time_last_checkpoint);
646 result = osd_scrub_file_store(scrub);
648 CERROR("%.16s: fail to osd_scrub_post, rc = %d\n",
649 LDISKFS_SB(osd_scrub2sb(scrub))->s_es->s_volume_name,
651 up_write(&scrub->os_rwsem);
656 /* iteration engine */
658 struct osd_iit_param {
659 struct super_block *sb;
660 struct buffer_head *bitmap;
666 typedef int (*osd_iit_next_policy)(struct osd_thread_info *info,
667 struct osd_device *dev,
668 struct osd_iit_param *param,
669 struct osd_idmap_cache **oic,
672 typedef int (*osd_iit_exec_policy)(struct osd_thread_info *info,
673 struct osd_device *dev,
674 struct osd_iit_param *param,
675 struct osd_idmap_cache *oic,
676 int *noslot, int rc);
678 static int osd_iit_next(struct osd_iit_param *param, __u32 *pos)
680 param->offset = ldiskfs_find_next_bit(param->bitmap->b_data,
681 LDISKFS_INODES_PER_GROUP(param->sb), param->offset);
682 if (param->offset >= LDISKFS_INODES_PER_GROUP(param->sb)) {
683 *pos = 1 + (param->bg+1) * LDISKFS_INODES_PER_GROUP(param->sb);
684 return SCRUB_NEXT_BREAK;
686 *pos = param->gbase + param->offset;
692 * \retval SCRUB_NEXT_OSTOBJ_OLD: FID-on-OST
693 * \retval 0: FID-on-MDT
695 static int osd_scrub_check_local_fldb(struct osd_thread_info *info,
696 struct osd_device *dev,
699 /* XXX: The initial OI scrub will scan the top level /O to generate
700 * a small local FLDB according to the <seq>. If the given FID
701 * is in the local FLDB, then it is FID-on-OST; otherwise it's
702 * quite possible for FID-on-MDT. */
706 static int osd_iit_iget(struct osd_thread_info *info, struct osd_device *dev,
707 struct lu_fid *fid, struct osd_inode_id *lid, __u32 pos,
708 struct super_block *sb, bool scrub)
710 struct lustre_mdt_attrs *lma = &info->oti_mdt_attrs;
713 bool has_lma = false;
716 osd_id_gen(lid, pos, OSD_OII_NOGEN);
717 inode = osd_iget(info, dev, lid);
720 /* The inode may be removed after bitmap searching, or the
721 * file is new created without inode initialized yet. */
722 if (rc == -ENOENT || rc == -ESTALE)
723 RETURN(SCRUB_NEXT_CONTINUE);
725 CERROR("%.16s: fail to read inode, ino# = %u, rc = %d\n",
726 LDISKFS_SB(sb)->s_es->s_volume_name, pos, rc);
730 /* If the inode has no OI mapping, then it is special locally used,
731 * should be invisible to OI scrub or up layer LFSCK. */
732 if (ldiskfs_test_inode_state(inode, LDISKFS_STATE_LUSTRE_NO_OI))
733 GOTO(put, rc = SCRUB_NEXT_CONTINUE);
736 ldiskfs_test_inode_state(inode, LDISKFS_STATE_LUSTRE_NOSCRUB)) {
737 /* Only skip it for the first OI scrub accessing. */
738 ldiskfs_clear_inode_state(inode, LDISKFS_STATE_LUSTRE_NOSCRUB);
739 GOTO(put, rc = SCRUB_NEXT_NOSCRUB);
742 rc = osd_get_lma(info, inode, &info->oti_obj_dentry, lma);
745 if (lma->lma_compat & LMAC_NOT_IN_OI) {
746 ldiskfs_set_inode_state(inode,
747 LDISKFS_STATE_LUSTRE_NO_OI);
748 GOTO(put, rc = SCRUB_NEXT_CONTINUE);
751 if (fid_is_llog(&lma->lma_self_fid))
752 GOTO(put, rc = SCRUB_NEXT_CONTINUE);
754 *fid = lma->lma_self_fid;
755 if (fid_is_internal(&lma->lma_self_fid)) {
757 rc = SCRUB_NEXT_CONTINUE;
764 if (fid_is_namespace_visible(fid) && !fid_is_norm(fid))
767 if (lma->lma_compat & LMAC_FID_ON_OST || fid_is_last_id(fid))
768 GOTO(put, rc = SCRUB_NEXT_OSTOBJ);
770 if (fid_is_idif(fid))
771 GOTO(put, rc = SCRUB_NEXT_OSTOBJ_OLD);
773 if (lma->lma_incompat & LMAI_AGENT)
774 GOTO(put, rc = SCRUB_NEXT_CONTINUE);
776 /* Here, it may be MDT-object, or may be 2.4 OST-object.
780 if (rc == -ENODATA || rc == 0) {
781 rc = osd_get_idif(info, inode, &info->oti_obj_dentry, fid);
784 /* It is old 2.x (x <= 3) or 1.8 OST-object. */
785 rc = SCRUB_NEXT_OSTOBJ_OLD;
791 /* It is FID-on-OST, but we do not know how
792 * to generate its FID, ignore it directly. */
793 rc = SCRUB_NEXT_CONTINUE;
795 /* It is 2.4 OST-object. */
796 rc = SCRUB_NEXT_OSTOBJ_OLD;
804 if (dev->od_handle_nolma) {
805 lu_igif_build(fid, inode->i_ino,
806 inode->i_generation);
808 rc = SCRUB_NEXT_NOLMA;
812 /* It may be FID-on-OST, or may be FID for
813 * non-MDT0, anyway, we do not know how to
814 * generate its FID, ignore it directly. */
815 rc = SCRUB_NEXT_CONTINUE;
820 /* For OI scrub case only: the object has LMA but has no ff
821 * (or ff crashed). It may be MDT-object, may be OST-object
822 * with crashed ff. The last check is local FLDB. */
823 rc = osd_scrub_check_local_fldb(info, dev, fid);
833 static int osd_scrub_next(struct osd_thread_info *info, struct osd_device *dev,
834 struct osd_iit_param *param,
835 struct osd_idmap_cache **oic, int noslot)
837 struct osd_scrub *scrub = &dev->od_scrub;
838 struct ptlrpc_thread *thread = &scrub->os_thread;
840 struct osd_inode_id *lid;
843 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_DELAY) && cfs_fail_val > 0) {
844 struct l_wait_info lwi;
846 lwi = LWI_TIMEOUT(cfs_time_seconds(cfs_fail_val), NULL, NULL);
847 l_wait_event(thread->t_ctl_waitq,
848 !cfs_list_empty(&scrub->os_inconsistent_items) ||
849 !thread_is_running(thread),
853 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_CRASH)) {
854 spin_lock(&scrub->os_lock);
855 thread_set_flags(thread, SVC_STOPPING);
856 spin_unlock(&scrub->os_lock);
857 return SCRUB_NEXT_CRASH;
860 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_FATAL))
861 return SCRUB_NEXT_FATAL;
863 if (unlikely(!thread_is_running(thread)))
864 return SCRUB_NEXT_EXIT;
866 if (!cfs_list_empty(&scrub->os_inconsistent_items)) {
867 struct osd_inconsistent_item *oii;
869 oii = cfs_list_entry(scrub->os_inconsistent_items.next,
870 struct osd_inconsistent_item, oii_list);
871 *oic = &oii->oii_cache;
872 scrub->os_in_prior = 1;
877 return SCRUB_NEXT_WAIT;
879 rc = osd_iit_next(param, &scrub->os_pos_current);
883 *oic = &scrub->os_oic;
884 fid = &(*oic)->oic_fid;
885 lid = &(*oic)->oic_lid;
886 rc = osd_iit_iget(info, dev, fid, lid,
887 scrub->os_pos_current, param->sb, true);
891 static int osd_preload_next(struct osd_thread_info *info,
892 struct osd_device *dev, struct osd_iit_param *param,
893 struct osd_idmap_cache **oic, int noslot)
895 struct osd_otable_cache *ooc = &dev->od_otable_it->ooi_cache;
896 struct osd_scrub *scrub;
897 struct ptlrpc_thread *thread;
900 rc = osd_iit_next(param, &ooc->ooc_pos_preload);
904 scrub = &dev->od_scrub;
905 thread = &scrub->os_thread;
906 if (thread_is_running(thread) &&
907 ooc->ooc_pos_preload >= scrub->os_pos_current)
908 return SCRUB_NEXT_EXIT;
910 rc = osd_iit_iget(info, dev,
911 &ooc->ooc_cache[ooc->ooc_producer_idx].oic_fid,
912 &ooc->ooc_cache[ooc->ooc_producer_idx].oic_lid,
913 ooc->ooc_pos_preload, param->sb, false);
914 /* If succeed, it needs to move forward; otherwise up layer LFSCK may
915 * ignore the failure, so it still need to skip the inode next time. */
916 ooc->ooc_pos_preload = param->gbase + ++(param->offset);
921 osd_scrub_wakeup(struct osd_scrub *scrub, struct osd_otable_it *it)
923 spin_lock(&scrub->os_lock);
924 if (osd_scrub_has_window(scrub, &it->ooi_cache) ||
925 !cfs_list_empty(&scrub->os_inconsistent_items) ||
926 it->ooi_waiting || !thread_is_running(&scrub->os_thread))
927 scrub->os_waiting = 0;
929 scrub->os_waiting = 1;
930 spin_unlock(&scrub->os_lock);
932 return !scrub->os_waiting;
935 static int osd_scrub_exec(struct osd_thread_info *info, struct osd_device *dev,
936 struct osd_iit_param *param,
937 struct osd_idmap_cache *oic, int *noslot, int rc)
939 struct l_wait_info lwi = { 0 };
940 struct osd_scrub *scrub = &dev->od_scrub;
941 struct scrub_file *sf = &scrub->os_file;
942 struct ptlrpc_thread *thread = &scrub->os_thread;
943 struct osd_otable_it *it = dev->od_otable_it;
944 struct osd_otable_cache *ooc = it ? &it->ooi_cache : NULL;
947 case SCRUB_NEXT_CONTINUE:
949 case SCRUB_NEXT_WAIT:
951 case SCRUB_NEXT_NOSCRUB:
952 down_write(&scrub->os_rwsem);
953 scrub->os_new_checked++;
954 sf->sf_items_noscrub++;
955 up_write(&scrub->os_rwsem);
959 rc = osd_scrub_check_update(info, dev, oic, rc);
963 rc = osd_scrub_checkpoint(scrub);
965 CERROR("%.16s: fail to checkpoint, pos = %u, rc = %d\n",
966 LDISKFS_SB(param->sb)->s_es->s_volume_name,
967 scrub->os_pos_current, rc);
968 /* Continue, as long as the scrub itself can go ahead. */
971 if (scrub->os_in_prior) {
972 scrub->os_in_prior = 0;
977 scrub->os_pos_current = param->gbase + ++(param->offset);
980 if (it != NULL && it->ooi_waiting &&
981 ooc->ooc_pos_preload < scrub->os_pos_current) {
982 spin_lock(&scrub->os_lock);
984 cfs_waitq_broadcast(&thread->t_ctl_waitq);
985 spin_unlock(&scrub->os_lock);
988 if (scrub->os_full_speed || rc == SCRUB_NEXT_CONTINUE)
991 if (osd_scrub_has_window(scrub, ooc)) {
996 l_wait_event(thread->t_ctl_waitq,
997 osd_scrub_wakeup(scrub, it),
1000 if (osd_scrub_has_window(scrub, ooc))
1007 static int osd_preload_exec(struct osd_thread_info *info,
1008 struct osd_device *dev, struct osd_iit_param *param,
1009 struct osd_idmap_cache *oic, int *noslot, int rc)
1011 struct osd_otable_cache *ooc = &dev->od_otable_it->ooi_cache;
1014 ooc->ooc_cached_items++;
1015 ooc->ooc_producer_idx = (ooc->ooc_producer_idx + 1) &
1016 ~OSD_OTABLE_IT_CACHE_MASK;
1018 return rc > 0 ? 0 : rc;
1021 #define SCRUB_IT_ALL 1
1022 #define SCRUB_IT_CRASH 2
1024 static int osd_inode_iteration(struct osd_thread_info *info,
1025 struct osd_device *dev, __u32 max, bool preload)
1027 osd_iit_next_policy next;
1028 osd_iit_exec_policy exec;
1031 struct osd_iit_param param;
1038 struct osd_scrub *scrub = &dev->od_scrub;
1040 next = osd_scrub_next;
1041 exec = osd_scrub_exec;
1042 pos = &scrub->os_pos_current;
1043 count = &scrub->os_new_checked;
1045 struct osd_otable_cache *ooc = &dev->od_otable_it->ooi_cache;
1047 next = osd_preload_next;
1048 exec = osd_preload_exec;
1049 pos = &ooc->ooc_pos_preload;
1050 count = &ooc->ooc_cached_items;
1052 param.sb = osd_sb(dev);
1053 limit = le32_to_cpu(LDISKFS_SB(param.sb)->s_es->s_inodes_count);
1055 while (*pos <= limit && *count < max) {
1056 struct osd_idmap_cache *oic = NULL;
1058 param.bg = (*pos - 1) / LDISKFS_INODES_PER_GROUP(param.sb);
1059 param.offset = (*pos - 1) % LDISKFS_INODES_PER_GROUP(param.sb);
1060 param.gbase = 1 + param.bg * LDISKFS_INODES_PER_GROUP(param.sb);
1061 param.bitmap = ldiskfs_read_inode_bitmap(param.sb, param.bg);
1062 if (param.bitmap == NULL) {
1063 CERROR("%.16s: fail to read bitmap for %u, "
1064 "scrub will stop, urgent mode\n",
1065 LDISKFS_SB(param.sb)->s_es->s_volume_name,
1070 while (param.offset < LDISKFS_INODES_PER_GROUP(param.sb) &&
1072 rc = next(info, dev, ¶m, &oic, noslot);
1074 case SCRUB_NEXT_BREAK:
1076 case SCRUB_NEXT_EXIT:
1077 brelse(param.bitmap);
1079 case SCRUB_NEXT_CRASH:
1080 brelse(param.bitmap);
1081 RETURN(SCRUB_IT_CRASH);
1082 case SCRUB_NEXT_FATAL:
1083 brelse(param.bitmap);
1087 rc = exec(info, dev, ¶m, oic, &noslot, rc);
1089 brelse(param.bitmap);
1095 brelse(param.bitmap);
1099 RETURN(SCRUB_IT_ALL);
1103 static int osd_otable_it_preload(const struct lu_env *env,
1104 struct osd_otable_it *it)
1106 struct osd_device *dev = it->ooi_dev;
1107 struct osd_scrub *scrub = &dev->od_scrub;
1108 struct osd_otable_cache *ooc = &it->ooi_cache;
1112 rc = osd_inode_iteration(osd_oti_get(env), dev,
1113 OSD_OTABLE_IT_CACHE_SIZE, true);
1114 if (rc == SCRUB_IT_ALL)
1115 it->ooi_all_cached = 1;
1117 CDEBUG(D_LFSCK, "OSD pre-loaded: max = %u, preload = %u, rc = %d\n",
1118 le32_to_cpu(LDISKFS_SB(osd_sb(dev))->s_es->s_inodes_count),
1119 ooc->ooc_pos_preload, rc);
1121 if (scrub->os_waiting && osd_scrub_has_window(scrub, ooc)) {
1122 scrub->os_waiting = 0;
1123 cfs_waitq_broadcast(&scrub->os_thread.t_ctl_waitq);
1126 RETURN(rc < 0 ? rc : ooc->ooc_cached_items);
1129 static int osd_scrub_main(void *args)
1132 struct osd_device *dev = (struct osd_device *)args;
1133 struct osd_scrub *scrub = &dev->od_scrub;
1134 struct ptlrpc_thread *thread = &scrub->os_thread;
1135 struct super_block *sb = osd_sb(dev);
1139 rc = lu_env_init(&env, LCT_LOCAL);
1141 CERROR("%.16s: OI scrub, fail to init env, rc = %d\n",
1142 LDISKFS_SB(sb)->s_es->s_volume_name, rc);
1146 rc = osd_scrub_prep(dev);
1148 CERROR("%.16s: OI scrub, fail to scrub prep, rc = %d\n",
1149 LDISKFS_SB(sb)->s_es->s_volume_name, rc);
1153 if (!scrub->os_full_speed) {
1154 struct l_wait_info lwi = { 0 };
1155 struct osd_otable_it *it = dev->od_otable_it;
1156 struct osd_otable_cache *ooc = &it->ooi_cache;
1158 l_wait_event(thread->t_ctl_waitq,
1159 it->ooi_user_ready || !thread_is_running(thread),
1161 if (unlikely(!thread_is_running(thread)))
1164 scrub->os_pos_current = ooc->ooc_pos_preload;
1167 CDEBUG(D_LFSCK, "OI scrub: flags = 0x%x, pos = %u\n",
1168 scrub->os_start_flags, scrub->os_pos_current);
1170 rc = osd_inode_iteration(osd_oti_get(&env), dev, ~0U, false);
1171 if (unlikely(rc == SCRUB_IT_CRASH))
1172 GOTO(out, rc = -EINVAL);
1176 osd_scrub_post(scrub, rc);
1177 CDEBUG(D_LFSCK, "OI scrub: stop, rc = %d, pos = %u\n",
1178 rc, scrub->os_pos_current);
1181 while (!cfs_list_empty(&scrub->os_inconsistent_items)) {
1182 struct osd_inconsistent_item *oii;
1184 oii = cfs_list_entry(scrub->os_inconsistent_items.next,
1185 struct osd_inconsistent_item, oii_list);
1186 cfs_list_del_init(&oii->oii_list);
1192 spin_lock(&scrub->os_lock);
1193 thread_set_flags(thread, SVC_STOPPED);
1194 cfs_waitq_broadcast(&thread->t_ctl_waitq);
1195 spin_unlock(&scrub->os_lock);
1199 /* initial OI scrub */
1201 typedef int (*scandir_t)(struct osd_thread_info *, struct osd_device *,
1202 struct dentry *, filldir_t filldir);
1204 static int osd_ios_varfid_fill(void *buf, const char *name, int namelen,
1205 loff_t offset, __u64 ino, unsigned d_type);
1208 osd_ios_general_scan(struct osd_thread_info *info, struct osd_device *dev,
1209 struct dentry *dentry, filldir_t filldir);
1211 osd_ios_ROOT_scan(struct osd_thread_info *info, struct osd_device *dev,
1212 struct dentry *dentry, filldir_t filldir);
1215 osd_ios_OBJECTS_scan(struct osd_thread_info *info, struct osd_device *dev,
1216 struct dentry *dentry, filldir_t filldir);
1219 OLF_SCAN_SUBITEMS = 0x0001,
1220 OLF_HIDE_FID = 0x0002,
1221 OLF_SHOW_NAME = 0x0004,
1226 struct lu_fid olm_fid;
1228 scandir_t olm_scandir;
1229 filldir_t olm_filldir;
1232 /* Add the new introduced local files in the list in the future. */
1233 static const struct osd_lf_map osd_lf_maps[] = {
1235 { CATLIST, { FID_SEQ_LOCAL_FILE, LLOG_CATALOGS_OID, 0 }, OLF_SHOW_NAME,
1239 { MOUNT_CONFIGS_DIR, { FID_SEQ_LOCAL_FILE, MGS_CONFIGS_OID, 0 },
1240 OLF_SCAN_SUBITEMS, osd_ios_general_scan,
1241 osd_ios_varfid_fill },
1243 /* NIDTBL_VERSIONS */
1244 { MGS_NIDTBL_DIR, { 0, 0, 0 }, OLF_SCAN_SUBITEMS,
1245 osd_ios_general_scan, osd_ios_varfid_fill },
1248 { "PENDING", { 0, 0, 0 }, 0, NULL, NULL },
1251 { "ROOT", { FID_SEQ_ROOT, 1, 0 },
1252 OLF_SCAN_SUBITEMS | OLF_HIDE_FID, osd_ios_ROOT_scan, NULL },
1254 /* changelog_catalog */
1255 { CHANGELOG_CATALOG, { 0, 0, 0 }, 0, NULL, NULL },
1257 /* changelog_users */
1258 { CHANGELOG_USERS, { 0, 0, 0 }, 0, NULL, NULL },
1261 { "fld", { FID_SEQ_LOCAL_FILE, FLD_INDEX_OID, 0 }, OLF_SHOW_NAME,
1265 { LAST_RCVD, { FID_SEQ_LOCAL_FILE, LAST_RECV_OID, 0 }, OLF_SHOW_NAME,
1268 /* lfsck_bookmark */
1269 { "lfsck_bookmark", { 0, 0, 0 }, 0, NULL, NULL },
1272 { LOV_OBJID, { FID_SEQ_LOCAL_FILE, MDD_LOV_OBJ_OID, 0 }, OLF_SHOW_NAME,
1276 { LOV_OBJSEQ, { FID_SEQ_LOCAL_FILE, MDD_LOV_OBJ_OSEQ, 0 },
1277 OLF_SHOW_NAME, NULL, NULL },
1280 { QMT_DIR, { 0, 0, 0 }, OLF_SCAN_SUBITEMS,
1281 osd_ios_general_scan, osd_ios_varfid_fill },
1284 { QSD_DIR, { 0, 0, 0 }, OLF_SCAN_SUBITEMS,
1285 osd_ios_general_scan, osd_ios_varfid_fill },
1288 { "seq_ctl", { FID_SEQ_LOCAL_FILE, FID_SEQ_CTL_OID, 0 },
1289 OLF_SHOW_NAME, NULL, NULL },
1292 { "seq_srv", { FID_SEQ_LOCAL_FILE, FID_SEQ_SRV_OID, 0 },
1293 OLF_SHOW_NAME, NULL, NULL },
1296 { HEALTH_CHECK, { FID_SEQ_LOCAL_FILE, OFD_HEALTH_CHECK_OID, 0 },
1297 OLF_SHOW_NAME, NULL, NULL },
1299 /* lfsck_namespace */
1300 { "lfsck_namespace", { 0, 0, 0 }, 0, NULL, NULL },
1302 /* OBJECTS, upgrade from old device */
1303 { OBJECTS, { 0, 0, 0 }, OLF_SCAN_SUBITEMS, osd_ios_OBJECTS_scan, NULL },
1305 /* lquota_v2.user, upgrade from old device */
1306 { "lquota_v2.user", { 0, 0, 0 }, 0, NULL, NULL },
1308 /* lquota_v2.group, upgrade from old device */
1309 { "lquota_v2.group", { 0, 0, 0 }, 0, NULL, NULL },
1311 /* LAST_GROUP, upgrade from old device */
1312 { "LAST_GROUP", { FID_SEQ_LOCAL_FILE, OFD_LAST_GROUP_OID, 0 },
1313 OLF_SHOW_NAME, NULL, NULL },
1315 { NULL, { 0, 0, 0 }, 0, NULL, NULL }
1318 struct osd_ios_item {
1319 cfs_list_t oii_list;
1320 struct dentry *oii_dentry;
1321 scandir_t oii_scandir;
1322 filldir_t oii_filldir;
1325 struct osd_ios_filldir_buf {
1326 struct osd_thread_info *oifb_info;
1327 struct osd_device *oifb_dev;
1328 struct dentry *oifb_dentry;
1331 static inline struct dentry *
1332 osd_ios_lookup_one_len(const char *name, struct dentry *parent, int namelen)
1334 struct dentry *dentry;
1336 dentry = ll_lookup_one_len(name, parent, namelen);
1337 if (!IS_ERR(dentry) && dentry->d_inode == NULL) {
1339 return ERR_PTR(-ENOENT);
1346 osd_ios_llogname2fid(struct lu_fid *fid, const char *name, int namelen)
1351 fid->f_seq = FID_SEQ_LLOG;
1353 id = id * 10 + name[i++] - '0';
1355 fid->f_oid = id & 0x00000000ffffffffULL;
1356 fid->f_ver = id >> 32;
1360 osd_ios_Oname2fid(struct lu_fid *fid, const char *name, int namelen)
1366 seq = seq * 10 + name[i++] - '0';
1368 lu_last_id_fid(fid, seq);
1372 osd_ios_new_item(struct osd_device *dev, struct dentry *dentry,
1373 scandir_t scandir, filldir_t filldir)
1375 struct osd_ios_item *item;
1377 OBD_ALLOC_PTR(item);
1381 CFS_INIT_LIST_HEAD(&item->oii_list);
1382 item->oii_dentry = dget(dentry);
1383 item->oii_scandir = scandir;
1384 item->oii_filldir = filldir;
1385 cfs_list_add_tail(&item->oii_list, &dev->od_ios_list);
1390 * osd_ios_scan_one() - check/fix LMA FID and OI entry for one inode
1392 * The passed \a inode's \a fid is verified against the LMA FID. If the \a fid
1393 * is NULL or is empty the IGIF FID is used. The FID is verified in the OI to
1394 * reference the inode, or fixed if it is missing or references another inode.
1397 osd_ios_scan_one(struct osd_thread_info *info, struct osd_device *dev,
1398 struct inode *inode, const struct lu_fid *fid, int flags)
1400 struct lustre_mdt_attrs *lma = &info->oti_mdt_attrs;
1401 struct osd_inode_id *id = &info->oti_id;
1402 struct osd_inode_id *id2 = &info->oti_id2;
1403 struct osd_scrub *scrub = &dev->od_scrub;
1404 struct scrub_file *sf = &scrub->os_file;
1409 rc = osd_get_lma(info, inode, &info->oti_obj_dentry, lma);
1410 if (rc != 0 && rc != -ENODATA)
1413 osd_id_gen(id, inode->i_ino, inode->i_generation);
1414 if (rc == -ENODATA) {
1415 if (fid == NULL || fid_is_zero(fid) || flags & OLF_HIDE_FID)
1416 lu_igif_build(&tfid, inode->i_ino, inode->i_generation);
1419 rc = osd_ea_fid_set(info, inode, &tfid, 0, 0);
1423 if (lma->lma_compat & LMAC_NOT_IN_OI)
1426 tfid = lma->lma_self_fid;
1429 rc = osd_oi_lookup(info, dev, &tfid, id2, 0);
1434 rc = osd_scrub_refresh_mapping(info, dev, &tfid, id,
1435 DTO_INDEX_INSERT, 0);
1442 if (osd_id_eq_strict(id, id2))
1445 if (!(sf->sf_flags & SF_INCONSISTENT)) {
1446 osd_scrub_file_reset(scrub,
1447 LDISKFS_SB(osd_sb(dev))->s_es->s_uuid,
1449 rc = osd_scrub_file_store(scrub);
1454 rc = osd_scrub_refresh_mapping(info, dev, &tfid, id,
1455 DTO_INDEX_UPDATE, 0);
1462 static int osd_ios_varfid_fill(void *buf, const char *name, int namelen,
1463 loff_t offset, __u64 ino, unsigned d_type)
1465 struct osd_ios_filldir_buf *fill_buf = buf;
1466 struct osd_device *dev = fill_buf->oifb_dev;
1467 struct dentry *child;
1471 /* skip any '.' started names */
1475 child = osd_ios_lookup_one_len(name, fill_buf->oifb_dentry, namelen);
1477 RETURN(PTR_ERR(child));
1479 rc = osd_ios_scan_one(fill_buf->oifb_info, dev, child->d_inode,
1481 if (rc == 0 && S_ISDIR(child->d_inode->i_mode))
1482 rc = osd_ios_new_item(dev, child, osd_ios_general_scan,
1483 osd_ios_varfid_fill);
1489 static int osd_ios_root_fill(void *buf, const char *name, int namelen,
1490 loff_t offset, __u64 ino, unsigned d_type)
1492 struct osd_ios_filldir_buf *fill_buf = buf;
1493 struct osd_device *dev = fill_buf->oifb_dev;
1494 const struct osd_lf_map *map;
1495 struct dentry *child;
1499 /* skip any '.' started names */
1503 for (map = osd_lf_maps; map->olm_name != NULL; map++) {
1504 if (strlen(map->olm_name) != namelen)
1507 if (strncmp(map->olm_name, name, namelen) == 0)
1511 if (map->olm_name == NULL)
1514 child = osd_ios_lookup_one_len(name, fill_buf->oifb_dentry, namelen);
1516 RETURN(PTR_ERR(child));
1518 rc = osd_ios_scan_one(fill_buf->oifb_info, dev, child->d_inode,
1519 &map->olm_fid, map->olm_flags);
1520 if (rc == 0 && map->olm_flags & OLF_SCAN_SUBITEMS)
1521 rc = osd_ios_new_item(dev, child, map->olm_scandir,
1529 osd_ios_general_scan(struct osd_thread_info *info, struct osd_device *dev,
1530 struct dentry *dentry, filldir_t filldir)
1532 struct osd_ios_filldir_buf buf = { info, dev, dentry };
1533 struct file *filp = &info->oti_it_ea.oie_file;
1534 struct inode *inode = dentry->d_inode;
1535 const struct file_operations *fops = inode->i_fop;
1539 LASSERT(filldir != NULL);
1542 filp->f_dentry = dentry;
1543 filp->f_mode = FMODE_64BITHASH;
1544 filp->f_mapping = inode->i_mapping;
1546 filp->private_data = NULL;
1548 rc = fops->readdir(filp, &buf, filldir);
1549 fops->release(inode, filp);
1555 osd_ios_ROOT_scan(struct osd_thread_info *info, struct osd_device *dev,
1556 struct dentry *dentry, filldir_t filldir)
1558 struct osd_scrub *scrub = &dev->od_scrub;
1559 struct scrub_file *sf = &scrub->os_file;
1560 struct dentry *child;
1564 /* It is existing MDT0 device. We only allow the case of object without
1565 * LMA to happen on the MDT0, which is usually for old 1.8 MDT. Then we
1566 * can generate IGIF mode FID for the object and related OI mapping. If
1567 * it is on other MDTs, then becuase file-level backup/restore, related
1568 * OI mapping may be invalid already, we do not know which is the right
1569 * FID for the object. We only allow IGIF objects to reside on the MDT0.
1571 * XXX: For the case of object on non-MDT0 device with neither LMA nor
1572 * "fid" xattr, then something crashed. We cannot re-generate the
1573 * FID directly, instead, the OI scrub will scan the OI structure
1574 * and try to re-generate the LMA from the OI mapping. But if the
1575 * OI mapping crashed or lost also, then we have to give up under
1576 * double failure cases. */
1577 dev->od_handle_nolma = 1;
1578 child = osd_ios_lookup_one_len(dot_lustre_name, dentry,
1579 strlen(dot_lustre_name));
1580 if (IS_ERR(child)) {
1581 rc = PTR_ERR(child);
1582 if (rc == -ENOENT) {
1583 /* It is 1.8 MDT device. */
1584 if (!(sf->sf_flags & SF_UPGRADE)) {
1585 osd_scrub_file_reset(scrub,
1586 LDISKFS_SB(osd_sb(dev))->s_es->s_uuid,
1588 rc = osd_scrub_file_store(scrub);
1594 /* For lustre-2.x (x <= 3), the ".lustre" has NO FID-in-LMA,
1595 * so the client will get IGIF for the ".lustre" object when
1598 * From the OI scrub view, when the MDT upgrade to Lustre-2.4,
1599 * it does not know whether there are some old clients cached
1600 * the ".lustre" IGIF during the upgrading. Two choices:
1602 * 1) Generate IGIF-in-LMA and IGIF-in-OI for the ".lustre".
1603 * It will allow the old connected clients to access the
1604 * ".lustre" with cached IGIF. But it will cause others
1605 * on the MDT failed to check "fid_is_dot_lustre()".
1607 * 2) Use fixed FID {FID_SEQ_DOT_LUSTRE, FID_OID_DOT_LUSTRE, 0}
1608 * for ".lustre" in spite of whether there are some clients
1609 * cached the ".lustre" IGIF or not. It enables the check
1610 * "fid_is_dot_lustre()" on the MDT, although it will cause
1611 * that the old connected clients cannot access the ".lustre"
1612 * with the cached IGIF.
1614 * Usually, it is rare case for the old connected clients
1615 * to access the ".lustre" with cached IGIF. So we prefer
1616 * to the solution 2). */
1617 rc = osd_ios_scan_one(info, dev, child->d_inode,
1618 &LU_DOT_LUSTRE_FID, 0);
1626 osd_ios_OBJECTS_scan(struct osd_thread_info *info, struct osd_device *dev,
1627 struct dentry *dentry, filldir_t filldir)
1629 struct dentry *child;
1633 child = osd_ios_lookup_one_len(ADMIN_USR, dentry, strlen(ADMIN_USR));
1634 if (!IS_ERR(child)) {
1635 rc = osd_ios_scan_one(info, dev, child->d_inode, NULL, 0);
1638 rc = PTR_ERR(child);
1641 if (rc != 0 && rc != -ENOENT)
1644 child = osd_ios_lookup_one_len(ADMIN_GRP, dentry, strlen(ADMIN_GRP));
1645 if (!IS_ERR(child)) {
1646 rc = osd_ios_scan_one(info, dev, child->d_inode, NULL, 0);
1649 rc = PTR_ERR(child);
1658 static int osd_initial_OI_scrub(struct osd_thread_info *info,
1659 struct osd_device *dev)
1661 struct osd_ios_item *item = NULL;
1662 scandir_t scandir = osd_ios_general_scan;
1663 filldir_t filldir = osd_ios_root_fill;
1664 struct dentry *dentry = osd_sb(dev)->s_root;
1665 const struct osd_lf_map *map = osd_lf_maps;
1670 rc = scandir(info, dev, dentry, filldir);
1672 dput(item->oii_dentry);
1679 if (cfs_list_empty(&dev->od_ios_list))
1682 item = cfs_list_entry(dev->od_ios_list.next,
1683 struct osd_ios_item, oii_list);
1684 cfs_list_del_init(&item->oii_list);
1686 LASSERT(item->oii_scandir != NULL);
1687 scandir = item->oii_scandir;
1688 filldir = item->oii_filldir;
1689 dentry = item->oii_dentry;
1692 while (!cfs_list_empty(&dev->od_ios_list)) {
1693 item = cfs_list_entry(dev->od_ios_list.next,
1694 struct osd_ios_item, oii_list);
1695 cfs_list_del_init(&item->oii_list);
1696 dput(item->oii_dentry);
1703 /* There maybe the case that the object has been removed, but its OI
1704 * mapping is still in the OI file, such as the "CATALOGS" after MDT
1705 * file-level backup/restore. So here cleanup the stale OI mappings. */
1706 while (map->olm_name != NULL) {
1707 struct dentry *child;
1709 if (fid_is_zero(&map->olm_fid)) {
1714 child = osd_ios_lookup_one_len(map->olm_name,
1715 osd_sb(dev)->s_root,
1716 strlen(map->olm_name));
1719 else if (PTR_ERR(child) == -ENOENT)
1720 osd_scrub_refresh_mapping(info, dev, &map->olm_fid,
1721 NULL, DTO_INDEX_DELETE, 0);
1728 char *osd_lf_fid2name(const struct lu_fid *fid)
1730 const struct osd_lf_map *map = osd_lf_maps;
1732 while (map->olm_name != NULL) {
1733 if (!lu_fid_eq(fid, &map->olm_fid)) {
1738 if (map->olm_flags & OLF_SHOW_NAME)
1739 return map->olm_name;
1747 /* OI scrub start/stop */
1749 static int do_osd_scrub_start(struct osd_device *dev, __u32 flags)
1751 struct osd_scrub *scrub = &dev->od_scrub;
1752 struct ptlrpc_thread *thread = &scrub->os_thread;
1753 struct l_wait_info lwi = { 0 };
1758 /* os_lock: sync status between stop and scrub thread */
1759 spin_lock(&scrub->os_lock);
1760 if (thread_is_running(thread)) {
1761 spin_unlock(&scrub->os_lock);
1763 } else if (unlikely(thread_is_stopping(thread))) {
1764 spin_unlock(&scrub->os_lock);
1765 l_wait_event(thread->t_ctl_waitq,
1766 thread_is_stopped(thread),
1770 spin_unlock(&scrub->os_lock);
1772 if (scrub->os_file.sf_status == SS_COMPLETED)
1775 scrub->os_start_flags = flags;
1776 thread_set_flags(thread, 0);
1777 rc = PTR_ERR(kthread_run(osd_scrub_main, dev, "OI_scrub"));
1778 if (IS_ERR_VALUE(rc)) {
1779 CERROR("%.16s: cannot start iteration thread, rc = %d\n",
1780 LDISKFS_SB(osd_sb(dev))->s_es->s_volume_name, rc);
1784 l_wait_event(thread->t_ctl_waitq,
1785 thread_is_running(thread) || thread_is_stopped(thread),
1791 int osd_scrub_start(struct osd_device *dev)
1796 /* od_otable_mutex: prevent curcurrent start/stop */
1797 mutex_lock(&dev->od_otable_mutex);
1798 rc = do_osd_scrub_start(dev, SS_AUTO);
1799 mutex_unlock(&dev->od_otable_mutex);
1801 RETURN(rc == -EALREADY ? 0 : rc);
1804 static void do_osd_scrub_stop(struct osd_scrub *scrub)
1806 struct ptlrpc_thread *thread = &scrub->os_thread;
1807 struct l_wait_info lwi = { 0 };
1809 /* os_lock: sync status between stop and scrub thread */
1810 spin_lock(&scrub->os_lock);
1811 if (!thread_is_init(thread) && !thread_is_stopped(thread)) {
1812 thread_set_flags(thread, SVC_STOPPING);
1813 spin_unlock(&scrub->os_lock);
1814 cfs_waitq_broadcast(&thread->t_ctl_waitq);
1815 l_wait_event(thread->t_ctl_waitq,
1816 thread_is_stopped(thread),
1818 /* Do not skip the last lock/unlock, which can guarantee that
1819 * the caller cannot return until the OI scrub thread exit. */
1820 spin_lock(&scrub->os_lock);
1822 spin_unlock(&scrub->os_lock);
1825 static void osd_scrub_stop(struct osd_device *dev)
1827 /* od_otable_mutex: prevent curcurrent start/stop */
1828 mutex_lock(&dev->od_otable_mutex);
1829 dev->od_scrub.os_paused = 1;
1830 do_osd_scrub_stop(&dev->od_scrub);
1831 mutex_unlock(&dev->od_otable_mutex);
1834 /* OI scrub setup/cleanup */
1836 static const char osd_scrub_name[] = "OI_scrub";
1838 int osd_scrub_setup(const struct lu_env *env, struct osd_device *dev)
1840 struct osd_thread_info *info = osd_oti_get(env);
1841 struct osd_scrub *scrub = &dev->od_scrub;
1842 struct lvfs_run_ctxt *ctxt = &scrub->os_ctxt;
1843 struct scrub_file *sf = &scrub->os_file;
1844 struct super_block *sb = osd_sb(dev);
1845 struct ldiskfs_super_block *es = LDISKFS_SB(sb)->s_es;
1846 struct lvfs_run_ctxt saved;
1848 struct inode *inode;
1849 struct lu_fid *fid = &info->oti_fid;
1854 memset(scrub, 0, sizeof(*scrub));
1855 OBD_SET_CTXT_MAGIC(ctxt);
1856 ctxt->pwdmnt = dev->od_mnt;
1857 ctxt->pwd = dev->od_mnt->mnt_root;
1858 ctxt->fs = get_ds();
1860 cfs_waitq_init(&scrub->os_thread.t_ctl_waitq);
1861 init_rwsem(&scrub->os_rwsem);
1862 spin_lock_init(&scrub->os_lock);
1863 CFS_INIT_LIST_HEAD(&scrub->os_inconsistent_items);
1865 push_ctxt(&saved, ctxt, NULL);
1866 filp = filp_open(osd_scrub_name, O_RDWR | O_CREAT, 0644);
1868 pop_ctxt(&saved, ctxt, NULL);
1869 RETURN(PTR_ERR(filp));
1872 inode = filp->f_dentry->d_inode;
1873 ldiskfs_set_inode_state(inode, LDISKFS_STATE_LUSTRE_NO_OI);
1874 /* 'What the @fid is' is not imporatant, because the object
1875 * has no OI mapping, and only is visible inside the OSD.*/
1876 lu_igif_build(fid, inode->i_ino, inode->i_generation);
1877 rc = osd_ea_fid_set(info, inode, fid, LMAC_NOT_IN_OI, 0);
1879 filp_close(filp, 0);
1880 pop_ctxt(&saved, ctxt, NULL);
1884 scrub->os_inode = igrab(inode);
1885 filp_close(filp, 0);
1886 pop_ctxt(&saved, ctxt, NULL);
1888 rc = osd_scrub_file_load(scrub);
1889 if (rc == -ENOENT) {
1890 osd_scrub_file_init(scrub, es->s_uuid);
1892 } else if (rc != 0) {
1895 if (memcmp(sf->sf_uuid, es->s_uuid, 16) != 0) {
1896 osd_scrub_file_reset(scrub, es->s_uuid,SF_INCONSISTENT);
1898 } else if (sf->sf_status == SS_SCANNING) {
1899 sf->sf_status = SS_CRASHED;
1904 if (sf->sf_pos_last_checkpoint != 0)
1905 scrub->os_pos_current = sf->sf_pos_last_checkpoint + 1;
1907 scrub->os_pos_current = LDISKFS_FIRST_INO(sb) + 1;
1910 rc = osd_scrub_file_store(scrub);
1915 /* Initialize OI files. */
1916 rc = osd_oi_init(info, dev);
1920 rc = osd_initial_OI_scrub(info, dev);
1922 if ((sf->sf_flags & SF_UPGRADE) &&
1923 !(sf->sf_flags & SF_INCONSISTENT))
1924 /* The 'od_igif_inoi' will be set after the
1925 * upgrading completed, needs NOT remount. */
1926 dev->od_igif_inoi = 0;
1928 /* The 'od_igif_inoi' will be set under the
1930 * 1) new created system, or
1931 * 2) restored from file-level backup, or
1932 * 3) the upgrading completed.
1934 * The 'od_igif_inoi' may be cleared by OI scrub
1935 * later if found that the system is upgrading. */
1936 dev->od_igif_inoi = 1;
1938 if (!dev->od_noscrub &&
1939 ((sf->sf_status == SS_PAUSED) ||
1940 (sf->sf_status == SS_CRASHED &&
1941 sf->sf_flags & (SF_RECREATED | SF_INCONSISTENT |
1942 SF_UPGRADE | SF_AUTO)) ||
1943 (sf->sf_status == SS_INIT &&
1944 sf->sf_flags & (SF_RECREATED | SF_INCONSISTENT |
1946 rc = osd_scrub_start(dev);
1949 /* it is possible that dcache entries may keep objects after they are
1950 * deleted by OSD. While it looks safe this can cause object data to
1951 * stay until umount causing failures in tests calculating free space,
1952 * e.g. replay-ost-single. Since those dcache entries are not used
1953 * anymore let's just free them after use here */
1954 shrink_dcache_sb(sb);
1959 void osd_scrub_cleanup(const struct lu_env *env, struct osd_device *dev)
1961 struct osd_scrub *scrub = &dev->od_scrub;
1963 LASSERT(dev->od_otable_it == NULL);
1965 if (scrub->os_inode != NULL) {
1966 osd_scrub_stop(dev);
1967 iput(scrub->os_inode);
1968 scrub->os_inode = NULL;
1970 if (dev->od_oi_table != NULL)
1971 osd_oi_fini(osd_oti_get(env), dev);
1974 /* object table based iteration APIs */
1976 static struct dt_it *osd_otable_it_init(const struct lu_env *env,
1977 struct dt_object *dt, __u32 attr,
1978 struct lustre_capa *capa)
1980 enum dt_otable_it_flags flags = attr >> DT_OTABLE_IT_FLAGS_SHIFT;
1981 enum dt_otable_it_valid valid = attr & ~DT_OTABLE_IT_FLAGS_MASK;
1982 struct osd_device *dev = osd_dev(dt->do_lu.lo_dev);
1983 struct osd_scrub *scrub = &dev->od_scrub;
1984 struct osd_otable_it *it;
1989 /* od_otable_mutex: prevent curcurrent init/fini */
1990 mutex_lock(&dev->od_otable_mutex);
1991 if (dev->od_otable_it != NULL)
1992 GOTO(out, it = ERR_PTR(-EALREADY));
1996 GOTO(out, it = ERR_PTR(-ENOMEM));
1998 dev->od_otable_it = it;
2000 it->ooi_cache.ooc_consumer_idx = -1;
2001 if (flags & DOIF_OUTUSED)
2002 it->ooi_used_outside = 1;
2004 if (flags & DOIF_RESET)
2007 if (valid & DOIV_ERROR_HANDLE) {
2008 if (flags & DOIF_FAILOUT)
2009 start |= SS_SET_FAILOUT;
2011 start |= SS_CLEAR_FAILOUT;
2014 rc = do_osd_scrub_start(dev, start);
2015 if (rc < 0 && rc != -EALREADY) {
2016 dev->od_otable_it = NULL;
2018 GOTO(out, it = ERR_PTR(rc));
2021 it->ooi_cache.ooc_pos_preload = scrub->os_pos_current;
2026 mutex_unlock(&dev->od_otable_mutex);
2027 return (struct dt_it *)it;
2030 static void osd_otable_it_fini(const struct lu_env *env, struct dt_it *di)
2032 struct osd_otable_it *it = (struct osd_otable_it *)di;
2033 struct osd_device *dev = it->ooi_dev;
2035 /* od_otable_mutex: prevent curcurrent init/fini */
2036 mutex_lock(&dev->od_otable_mutex);
2037 do_osd_scrub_stop(&dev->od_scrub);
2038 LASSERT(dev->od_otable_it == it);
2040 dev->od_otable_it = NULL;
2041 mutex_unlock(&dev->od_otable_mutex);
2045 static int osd_otable_it_get(const struct lu_env *env,
2046 struct dt_it *di, const struct dt_key *key)
2051 static void osd_otable_it_put(const struct lu_env *env, struct dt_it *di)
2056 osd_otable_it_wakeup(struct osd_scrub *scrub, struct osd_otable_it *it)
2058 spin_lock(&scrub->os_lock);
2059 if (it->ooi_cache.ooc_pos_preload < scrub->os_pos_current ||
2060 scrub->os_waiting ||
2061 !thread_is_running(&scrub->os_thread))
2062 it->ooi_waiting = 0;
2064 it->ooi_waiting = 1;
2065 spin_unlock(&scrub->os_lock);
2067 return !it->ooi_waiting;
2070 static int osd_otable_it_next(const struct lu_env *env, struct dt_it *di)
2072 struct osd_otable_it *it = (struct osd_otable_it *)di;
2073 struct osd_device *dev = it->ooi_dev;
2074 struct osd_scrub *scrub = &dev->od_scrub;
2075 struct osd_otable_cache *ooc = &it->ooi_cache;
2076 struct ptlrpc_thread *thread = &scrub->os_thread;
2077 struct l_wait_info lwi = { 0 };
2081 LASSERT(it->ooi_user_ready);
2084 if (!thread_is_running(thread) && !it->ooi_used_outside)
2087 if (ooc->ooc_cached_items > 0) {
2088 ooc->ooc_cached_items--;
2089 ooc->ooc_consumer_idx = (ooc->ooc_consumer_idx + 1) &
2090 ~OSD_OTABLE_IT_CACHE_MASK;
2094 if (it->ooi_all_cached) {
2095 l_wait_event(thread->t_ctl_waitq,
2096 !thread_is_running(thread),
2101 if (scrub->os_waiting && osd_scrub_has_window(scrub, ooc)) {
2102 spin_lock(&scrub->os_lock);
2103 scrub->os_waiting = 0;
2104 cfs_waitq_broadcast(&scrub->os_thread.t_ctl_waitq);
2105 spin_unlock(&scrub->os_lock);
2108 if (it->ooi_cache.ooc_pos_preload >= scrub->os_pos_current)
2109 l_wait_event(thread->t_ctl_waitq,
2110 osd_otable_it_wakeup(scrub, it),
2113 if (!thread_is_running(thread) && !it->ooi_used_outside)
2116 rc = osd_otable_it_preload(env, it);
2123 static struct dt_key *osd_otable_it_key(const struct lu_env *env,
2124 const struct dt_it *di)
2129 static int osd_otable_it_key_size(const struct lu_env *env,
2130 const struct dt_it *di)
2132 return sizeof(__u64);
2135 static int osd_otable_it_rec(const struct lu_env *env, const struct dt_it *di,
2136 struct dt_rec *rec, __u32 attr)
2138 struct osd_otable_it *it = (struct osd_otable_it *)di;
2139 struct osd_otable_cache *ooc = &it->ooi_cache;
2141 *(struct lu_fid *)rec = ooc->ooc_cache[ooc->ooc_consumer_idx].oic_fid;
2143 /* Filter out Invald FID already. */
2144 LASSERTF(fid_is_sane((struct lu_fid *)rec),
2145 "Invalid FID "DFID", p_idx = %d, c_idx = %d\n",
2146 PFID((struct lu_fid *)rec),
2147 ooc->ooc_producer_idx, ooc->ooc_consumer_idx);
2152 static __u64 osd_otable_it_store(const struct lu_env *env,
2153 const struct dt_it *di)
2155 struct osd_otable_it *it = (struct osd_otable_it *)di;
2156 struct osd_otable_cache *ooc = &it->ooi_cache;
2159 if (it->ooi_user_ready && ooc->ooc_consumer_idx != -1)
2160 hash = ooc->ooc_cache[ooc->ooc_consumer_idx].oic_lid.oii_ino;
2162 hash = ooc->ooc_pos_preload;
2167 * Set the OSD layer iteration start position as the specified hash.
2169 static int osd_otable_it_load(const struct lu_env *env,
2170 const struct dt_it *di, __u64 hash)
2172 struct osd_otable_it *it = (struct osd_otable_it *)di;
2173 struct osd_device *dev = it->ooi_dev;
2174 struct osd_otable_cache *ooc = &it->ooi_cache;
2175 struct osd_scrub *scrub = &dev->od_scrub;
2179 /* Forbid to set iteration position after iteration started. */
2180 if (it->ooi_user_ready)
2183 if (hash > OSD_OTABLE_MAX_HASH)
2184 hash = OSD_OTABLE_MAX_HASH;
2186 ooc->ooc_pos_preload = hash;
2187 if (ooc->ooc_pos_preload <= LDISKFS_FIRST_INO(osd_sb(dev)))
2188 ooc->ooc_pos_preload = LDISKFS_FIRST_INO(osd_sb(dev)) + 1;
2190 it->ooi_user_ready = 1;
2191 if (!scrub->os_full_speed)
2192 cfs_waitq_broadcast(&scrub->os_thread.t_ctl_waitq);
2194 /* Unplug OSD layer iteration by the first next() call. */
2195 rc = osd_otable_it_next(env, (struct dt_it *)it);
2200 static int osd_otable_it_key_rec(const struct lu_env *env,
2201 const struct dt_it *di, void *key_rec)
2206 const struct dt_index_operations osd_otable_ops = {
2208 .init = osd_otable_it_init,
2209 .fini = osd_otable_it_fini,
2210 .get = osd_otable_it_get,
2211 .put = osd_otable_it_put,
2212 .next = osd_otable_it_next,
2213 .key = osd_otable_it_key,
2214 .key_size = osd_otable_it_key_size,
2215 .rec = osd_otable_it_rec,
2216 .store = osd_otable_it_store,
2217 .load = osd_otable_it_load,
2218 .key_rec = osd_otable_it_key_rec,
2222 /* high priority inconsistent items list APIs */
2224 int osd_oii_insert(struct osd_device *dev, struct osd_idmap_cache *oic,
2227 struct osd_inconsistent_item *oii;
2228 struct osd_scrub *scrub = &dev->od_scrub;
2229 struct ptlrpc_thread *thread = &scrub->os_thread;
2234 if (unlikely(oii == NULL))
2237 CFS_INIT_LIST_HEAD(&oii->oii_list);
2238 oii->oii_cache = *oic;
2239 oii->oii_insert = insert;
2241 spin_lock(&scrub->os_lock);
2242 if (unlikely(!thread_is_running(thread))) {
2243 spin_unlock(&scrub->os_lock);
2248 if (cfs_list_empty(&scrub->os_inconsistent_items))
2250 cfs_list_add_tail(&oii->oii_list, &scrub->os_inconsistent_items);
2251 spin_unlock(&scrub->os_lock);
2254 cfs_waitq_broadcast(&thread->t_ctl_waitq);
2259 int osd_oii_lookup(struct osd_device *dev, const struct lu_fid *fid,
2260 struct osd_inode_id *id)
2262 struct osd_scrub *scrub = &dev->od_scrub;
2263 struct osd_inconsistent_item *oii;
2266 spin_lock(&scrub->os_lock);
2267 cfs_list_for_each_entry(oii, &scrub->os_inconsistent_items, oii_list) {
2268 if (lu_fid_eq(fid, &oii->oii_cache.oic_fid)) {
2269 *id = oii->oii_cache.oic_lid;
2270 spin_unlock(&scrub->os_lock);
2274 spin_unlock(&scrub->os_lock);
2281 static const char *scrub_status_names[] = {
2292 static const char *scrub_flags_names[] = {
2300 static const char *scrub_param_names[] = {
2305 static int scrub_bits_dump(char **buf, int *len, int bits, const char *names[],
2313 rc = snprintf(*buf, *len, "%s:%c", prefix, bits != 0 ? ' ' : '\n');
2319 for (i = 0, flag = 1; bits != 0; i++, flag = 1 << i) {
2322 rc = snprintf(*buf, *len, "%s%c", names[i],
2323 bits != 0 ? ',' : '\n');
2334 static int scrub_time_dump(char **buf, int *len, __u64 time, const char *prefix)
2339 rc = snprintf(*buf, *len, "%s: "LPU64" seconds\n", prefix,
2340 cfs_time_current_sec() - time);
2342 rc = snprintf(*buf, *len, "%s: N/A\n", prefix);
2351 static int scrub_pos_dump(char **buf, int *len, __u64 pos, const char *prefix)
2356 rc = snprintf(*buf, *len, "%s: "LPU64"\n", prefix, pos);
2358 rc = snprintf(*buf, *len, "%s: N/A\n", prefix);
2367 int osd_scrub_dump(struct osd_device *dev, char *buf, int len)
2369 struct osd_scrub *scrub = &dev->od_scrub;
2370 struct scrub_file *sf = &scrub->os_file;
2377 down_read(&scrub->os_rwsem);
2378 rc = snprintf(buf, len,
2383 sf->sf_magic, (int)sf->sf_oi_count,
2384 scrub_status_names[sf->sf_status]);
2390 rc = scrub_bits_dump(&buf, &len, sf->sf_flags, scrub_flags_names,
2395 rc = scrub_bits_dump(&buf, &len, sf->sf_param, scrub_param_names,
2400 rc = scrub_time_dump(&buf, &len, sf->sf_time_last_complete,
2401 "time_since_last_completed");
2405 rc = scrub_time_dump(&buf, &len, sf->sf_time_latest_start,
2406 "time_since_latest_start");
2410 rc = scrub_time_dump(&buf, &len, sf->sf_time_last_checkpoint,
2411 "time_since_last_checkpoint");
2415 rc = scrub_pos_dump(&buf, &len, sf->sf_pos_latest_start,
2416 "latest_start_position");
2420 rc = scrub_pos_dump(&buf, &len, sf->sf_pos_last_checkpoint,
2421 "last_checkpoint_position");
2425 rc = scrub_pos_dump(&buf, &len, sf->sf_pos_first_inconsistent,
2426 "first_failure_position");
2430 checked = sf->sf_items_checked + scrub->os_new_checked;
2431 rc = snprintf(buf, len,
2432 "checked: "LPU64"\n"
2433 "updated: "LPU64"\n"
2435 "prior_updated: "LPU64"\n"
2436 "noscrub: "LPU64"\n"
2438 "success_count: %u\n",
2439 checked, sf->sf_items_updated, sf->sf_items_failed,
2440 sf->sf_items_updated_prior, sf->sf_items_noscrub,
2441 sf->sf_items_igif, sf->sf_success_count);
2448 if (thread_is_running(&scrub->os_thread)) {
2449 cfs_duration_t duration = cfs_time_current() -
2450 scrub->os_time_last_checkpoint;
2451 __u64 new_checked = scrub->os_new_checked * CFS_HZ;
2452 __u32 rtime = sf->sf_run_time +
2453 cfs_duration_sec(duration + HALF_SEC);
2456 do_div(new_checked, duration);
2458 do_div(speed, rtime);
2459 rc = snprintf(buf, len,
2460 "run_time: %u seconds\n"
2461 "average_speed: "LPU64" objects/sec\n"
2462 "real-time_speed: "LPU64" objects/sec\n"
2463 "current_position: %u\n",
2464 rtime, speed, new_checked, scrub->os_pos_current);
2466 if (sf->sf_run_time != 0)
2467 do_div(speed, sf->sf_run_time);
2468 rc = snprintf(buf, len,
2469 "run_time: %u seconds\n"
2470 "average_speed: "LPU64" objects/sec\n"
2471 "real-time_speed: N/A\n"
2472 "current_position: N/A\n",
2473 sf->sf_run_time, speed);
2483 up_read(&scrub->os_rwsem);