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_LFSCK
40 #include <lustre/lustre_idl.h>
41 #include <lustre_disk.h>
42 #include <dt_object.h>
43 #include <linux/xattr.h>
45 #include "osd_internal.h"
47 #include "osd_scrub.h"
49 #define HALF_SEC msecs_to_jiffies(MSEC_PER_SEC >> 1)
51 #define OSD_OTABLE_MAX_HASH 0x00000000ffffffffULL
53 #define SCRUB_NEXT_BREAK 1 /* exit current loop and process next group */
54 #define SCRUB_NEXT_CONTINUE 2 /* skip current object and process next bit */
55 #define SCRUB_NEXT_EXIT 3 /* exit all the loops */
56 #define SCRUB_NEXT_WAIT 4 /* wait for free cache slot */
57 #define SCRUB_NEXT_CRASH 5 /* simulate system crash during OI scrub */
58 #define SCRUB_NEXT_FATAL 6 /* simulate failure during OI scrub */
59 #define SCRUB_NEXT_NOSCRUB 7 /* new created object, no scrub on it */
60 #define SCRUB_NEXT_NOLMA 8 /* the inode has no FID-in-LMA */
61 #define SCRUB_NEXT_OSTOBJ 9 /* for OST-object */
62 #define SCRUB_NEXT_OSTOBJ_OLD 10 /* old OST-object, no LMA or no FID-on-OST
67 static inline struct osd_device *osd_scrub2dev(struct osd_scrub *scrub)
69 return container_of0(scrub, struct osd_device, od_scrub);
72 static inline struct super_block *osd_scrub2sb(struct osd_scrub *scrub)
74 return osd_sb(osd_scrub2dev(scrub));
77 static inline int osd_scrub_has_window(struct osd_scrub *scrub,
78 struct osd_otable_cache *ooc)
80 return scrub->os_pos_current < ooc->ooc_pos_preload + SCRUB_WINDOW_SIZE;
83 static inline const char *osd_scrub2name(struct osd_scrub *scrub)
85 return LDISKFS_SB(osd_scrub2sb(scrub))->s_es->s_volume_name;
89 * update/insert/delete the specified OI mapping (@fid @id) according to the ops
91 * \retval 1, changed nothing
92 * \retval 0, changed successfully
93 * \retval -ve, on error
95 static int osd_scrub_refresh_mapping(struct osd_thread_info *info,
96 struct osd_device *dev,
97 const struct lu_fid *fid,
98 const struct osd_inode_id *id,
100 enum oi_check_flags flags)
106 if (dev->od_scrub.os_file.sf_param & SP_DRYRUN && !force)
109 /* DTO_INDEX_INSERT is enough for other two ops:
110 * delete/update, but save stack. */
111 th = osd_journal_start_sb(osd_sb(dev), LDISKFS_HT_MISC,
112 osd_dto_credits_noquota[DTO_INDEX_INSERT]);
115 CDEBUG(D_LFSCK, "%s: fail to start trans for scrub op %d "
116 DFID" => %u/%u: rc = %d\n", osd_name(dev), ops,
117 PFID(fid), id->oii_ino, id->oii_gen, rc);
122 case DTO_INDEX_UPDATE:
123 rc = osd_oi_update(info, dev, fid, id, th, flags);
124 if (unlikely(rc == -ENOENT)) {
125 /* Some unlink thread may removed the OI mapping. */
129 case DTO_INDEX_INSERT:
130 rc = osd_oi_insert(info, dev, fid, id, th, flags);
131 if (unlikely(rc == -EEXIST)) {
133 /* XXX: There are trouble things when adding OI
134 * mapping for IGIF object, which may cause
135 * multiple objects to be mapped to the same
136 * IGIF formatted FID. Consider the following
139 * 1) The MDT is upgrading from 1.8 device.
140 * The OI scrub generates IGIF FID1 for the
141 * OBJ1 and adds the OI mapping.
143 * 2) For some reason, the OI scrub does not
144 * process all the IGIF objects completely.
146 * 3) The MDT is backuped and restored against
149 * 4) When the MDT mounts up, the OI scrub will
150 * try to rebuild the OI files. For some IGIF
151 * object, OBJ2, which was not processed by the
152 * OI scrub before the backup/restore, and the
153 * new generated IGIF formatted FID may be just
154 * the FID1, the same as OBJ1.
156 * Under such case, the OI scrub cannot know how
157 * to generate new FID for the OBJ2.
159 * Currently, we do nothing for that. One possible
160 * solution is to generate new normal FID for the
163 * Anyway, it is rare, only exists in theory. */
166 case DTO_INDEX_DELETE:
167 rc = osd_oi_delete(info, dev, fid, th, flags);
169 /* It is normal that the unlink thread has removed the
170 * OI mapping already. */
175 LASSERTF(0, "Unexpected ops %d\n", ops);
179 ldiskfs_journal_stop(th);
181 CDEBUG(D_LFSCK, "%s: fail to refresh OI map for scrub op %d "
182 DFID" => %u/%u: rc = %d\n", osd_name(dev), ops,
183 PFID(fid), id->oii_ino, id->oii_gen, rc);
188 /* OI_scrub file ops */
190 static void osd_scrub_file_to_cpu(struct scrub_file *des,
191 struct scrub_file *src)
193 memcpy(des->sf_uuid, src->sf_uuid, 16);
194 des->sf_flags = le64_to_cpu(src->sf_flags);
195 des->sf_magic = le32_to_cpu(src->sf_magic);
196 des->sf_status = le16_to_cpu(src->sf_status);
197 des->sf_param = le16_to_cpu(src->sf_param);
198 des->sf_time_last_complete =
199 le64_to_cpu(src->sf_time_last_complete);
200 des->sf_time_latest_start =
201 le64_to_cpu(src->sf_time_latest_start);
202 des->sf_time_last_checkpoint =
203 le64_to_cpu(src->sf_time_last_checkpoint);
204 des->sf_pos_latest_start =
205 le64_to_cpu(src->sf_pos_latest_start);
206 des->sf_pos_last_checkpoint =
207 le64_to_cpu(src->sf_pos_last_checkpoint);
208 des->sf_pos_first_inconsistent =
209 le64_to_cpu(src->sf_pos_first_inconsistent);
210 des->sf_items_checked =
211 le64_to_cpu(src->sf_items_checked);
212 des->sf_items_updated =
213 le64_to_cpu(src->sf_items_updated);
214 des->sf_items_failed =
215 le64_to_cpu(src->sf_items_failed);
216 des->sf_items_updated_prior =
217 le64_to_cpu(src->sf_items_updated_prior);
218 des->sf_run_time = le32_to_cpu(src->sf_run_time);
219 des->sf_success_count = le32_to_cpu(src->sf_success_count);
220 des->sf_oi_count = le16_to_cpu(src->sf_oi_count);
221 des->sf_internal_flags = le16_to_cpu(src->sf_internal_flags);
222 memcpy(des->sf_oi_bitmap, src->sf_oi_bitmap, SCRUB_OI_BITMAP_SIZE);
225 static void osd_scrub_file_to_le(struct scrub_file *des,
226 struct scrub_file *src)
228 memcpy(des->sf_uuid, src->sf_uuid, 16);
229 des->sf_flags = cpu_to_le64(src->sf_flags);
230 des->sf_magic = cpu_to_le32(src->sf_magic);
231 des->sf_status = cpu_to_le16(src->sf_status);
232 des->sf_param = cpu_to_le16(src->sf_param);
233 des->sf_time_last_complete =
234 cpu_to_le64(src->sf_time_last_complete);
235 des->sf_time_latest_start =
236 cpu_to_le64(src->sf_time_latest_start);
237 des->sf_time_last_checkpoint =
238 cpu_to_le64(src->sf_time_last_checkpoint);
239 des->sf_pos_latest_start =
240 cpu_to_le64(src->sf_pos_latest_start);
241 des->sf_pos_last_checkpoint =
242 cpu_to_le64(src->sf_pos_last_checkpoint);
243 des->sf_pos_first_inconsistent =
244 cpu_to_le64(src->sf_pos_first_inconsistent);
245 des->sf_items_checked =
246 cpu_to_le64(src->sf_items_checked);
247 des->sf_items_updated =
248 cpu_to_le64(src->sf_items_updated);
249 des->sf_items_failed =
250 cpu_to_le64(src->sf_items_failed);
251 des->sf_items_updated_prior =
252 cpu_to_le64(src->sf_items_updated_prior);
253 des->sf_run_time = cpu_to_le32(src->sf_run_time);
254 des->sf_success_count = cpu_to_le32(src->sf_success_count);
255 des->sf_oi_count = cpu_to_le16(src->sf_oi_count);
256 des->sf_internal_flags = cpu_to_le16(src->sf_internal_flags);
257 memcpy(des->sf_oi_bitmap, src->sf_oi_bitmap, SCRUB_OI_BITMAP_SIZE);
260 static void osd_scrub_file_init(struct osd_scrub *scrub, __u8 *uuid)
262 struct scrub_file *sf = &scrub->os_file;
264 memset(sf, 0, sizeof(*sf));
265 memcpy(sf->sf_uuid, uuid, 16);
266 sf->sf_magic = SCRUB_MAGIC_V1;
267 sf->sf_status = SS_INIT;
270 void osd_scrub_file_reset(struct osd_scrub *scrub, __u8 *uuid, __u64 flags)
272 struct scrub_file *sf = &scrub->os_file;
274 CDEBUG(D_LFSCK, "%.16s: reset OI scrub file, flags = "LPX64"\n",
275 osd_scrub2name(scrub), flags);
276 memcpy(sf->sf_uuid, uuid, 16);
277 sf->sf_status = SS_INIT;
278 sf->sf_flags |= flags;
280 sf->sf_time_latest_start = 0;
281 sf->sf_time_last_checkpoint = 0;
282 sf->sf_pos_latest_start = 0;
283 sf->sf_pos_last_checkpoint = 0;
284 sf->sf_pos_first_inconsistent = 0;
285 sf->sf_items_checked = 0;
286 sf->sf_items_updated = 0;
287 sf->sf_items_failed = 0;
288 if (!scrub->os_in_join)
289 sf->sf_items_updated_prior = 0;
291 sf->sf_items_noscrub = 0;
292 sf->sf_items_igif = 0;
295 static int osd_scrub_file_load(struct osd_scrub *scrub)
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 CDEBUG(D_LFSCK, "%.16s: invalid scrub magic "
308 "0x%x != 0x%x\n", osd_scrub2name(scrub),
309 sf->sf_magic, SCRUB_MAGIC_V1);
310 /* Process it as new scrub file. */
315 } else if (rc != 0) {
316 CDEBUG(D_LFSCK, "%.16s: fail to load scrub file, "
317 "expected = %d: rc = %d\n",
318 osd_scrub2name(scrub), len, rc);
322 /* return -ENOENT for empty scrub file case. */
329 int osd_scrub_file_store(struct osd_scrub *scrub)
331 struct osd_device *dev;
334 int len = sizeof(scrub->os_file_disk);
338 dev = container_of0(scrub, struct osd_device, od_scrub);
339 credits = osd_dto_credits_noquota[DTO_WRITE_BASE] +
340 osd_dto_credits_noquota[DTO_WRITE_BLOCK];
341 jh = osd_journal_start_sb(osd_sb(dev), LDISKFS_HT_MISC, credits);
344 CDEBUG(D_LFSCK, "%.16s: fail to start trans for scrub store: "
345 "rc = %d\n", osd_scrub2name(scrub), rc);
349 osd_scrub_file_to_le(&scrub->os_file_disk, &scrub->os_file);
350 rc = osd_ldiskfs_write_record(scrub->os_inode, &scrub->os_file_disk,
352 ldiskfs_journal_stop(jh);
354 CDEBUG(D_LFSCK, "%.16s: fail to store scrub file, "
355 "expected = %d: rc = %d\n",
356 osd_scrub2name(scrub), len, rc);
358 scrub->os_time_last_checkpoint = cfs_time_current();
359 scrub->os_time_next_checkpoint = scrub->os_time_last_checkpoint +
360 cfs_time_seconds(SCRUB_CHECKPOINT_INTERVAL);
365 osd_scrub_convert_ff(struct osd_thread_info *info, struct osd_device *dev,
366 struct inode *inode, const struct lu_fid *fid)
368 struct filter_fid_old *ff = &info->oti_ff;
369 struct dentry *dentry = &info->oti_obj_dentry;
373 bool removed = false;
377 if (dev->od_scrub.os_file.sf_param & SP_DRYRUN)
380 /* We want the LMA to fit into the 256-byte OST inode, so operate
382 * 1) read old XATTR_NAME_FID and save the parent FID;
383 * 2) delete the old XATTR_NAME_FID;
384 * 3) make new LMA and add it;
385 * 4) generate new XATTR_NAME_FID with the saved parent FID and add it.
387 * Making the LMA to fit into the 256-byte OST inode can save time for
388 * normal osd_check_lma() and for other OI scrub scanning in future.
389 * So it is worth to make some slow conversion here. */
390 jh = osd_journal_start_sb(osd_sb(dev), LDISKFS_HT_MISC,
391 osd_dto_credits_noquota[DTO_XATTR_SET] * 3);
394 CDEBUG(D_LFSCK, "%s: fail to start trans for convert ff "
395 DFID": rc = %d\n", osd_name(dev), PFID(fid), rc);
399 /* 1) read old XATTR_NAME_FID and save the parent FID */
400 rc = __osd_xattr_get(inode, dentry, XATTR_NAME_FID, ff, sizeof(*ff));
401 if (rc == sizeof(*ff)) {
402 /* 2) delete the old XATTR_NAME_FID */
403 ll_vfs_dq_init(inode);
404 rc = inode->i_op->removexattr(dentry, XATTR_NAME_FID);
409 } else if (unlikely(rc == -ENODATA)) {
411 } else if (rc != sizeof(struct filter_fid)) {
412 GOTO(stop, rc = -EINVAL);
415 /* 3) make new LMA and add it */
416 rc = osd_ea_fid_set(info, inode, fid, LMAC_FID_ON_OST, 0);
417 if (rc == 0 && reset)
418 size = sizeof(struct filter_fid);
419 else if (rc != 0 && removed)
420 /* If failed, we should try to add the old back. */
421 size = sizeof(struct filter_fid_old);
423 /* 4) generate new XATTR_NAME_FID with the saved parent FID and add it*/
427 rc1 = __osd_xattr_set(info, inode, XATTR_NAME_FID, ff, size,
429 if (rc1 != 0 && rc == 0)
436 ldiskfs_journal_stop(jh);
438 CDEBUG(D_LFSCK, "%s: fail to convert ff "DFID": rc = %d\n",
439 osd_name(dev), PFID(fid), rc);
444 osd_scrub_check_update(struct osd_thread_info *info, struct osd_device *dev,
445 struct osd_idmap_cache *oic, int val)
447 struct osd_scrub *scrub = &dev->od_scrub;
448 struct scrub_file *sf = &scrub->os_file;
449 struct lu_fid *fid = &oic->oic_fid;
450 struct osd_inode_id *lid = &oic->oic_lid;
451 struct osd_inode_id *lid2 = &info->oti_id;
452 struct osd_inconsistent_item *oii = NULL;
453 struct inode *inode = NULL;
454 int ops = DTO_INDEX_UPDATE;
457 bool converted = false;
460 down_write(&scrub->os_rwsem);
461 scrub->os_new_checked++;
465 if (scrub->os_in_prior)
466 oii = list_entry(oic, struct osd_inconsistent_item,
469 if (lid->oii_ino < sf->sf_pos_latest_start && oii == NULL)
472 if (fid_is_igif(fid))
475 if (val == SCRUB_NEXT_OSTOBJ_OLD) {
476 inode = osd_iget(info, dev, lid);
479 /* Someone removed the inode. */
480 if (rc == -ENOENT || rc == -ESTALE)
485 sf->sf_flags |= SF_UPGRADE;
486 sf->sf_internal_flags &= ~SIF_NO_HANDLE_OLD_FID;
487 dev->od_check_ff = 1;
488 rc = osd_scrub_convert_ff(info, dev, inode, fid);
495 if ((val == SCRUB_NEXT_NOLMA) &&
496 (!scrub->os_convert_igif || OBD_FAIL_CHECK(OBD_FAIL_FID_NOLMA)))
499 if ((oii != NULL && oii->oii_insert) || (val == SCRUB_NEXT_NOLMA))
502 rc = osd_oi_lookup(info, dev, fid, lid2,
503 (val == SCRUB_NEXT_OSTOBJ ||
504 val == SCRUB_NEXT_OSTOBJ_OLD) ? OI_KNOWN_ON_OST : 0);
506 if (rc != -ENOENT && rc != -ESTALE)
511 inode = osd_iget(info, dev, lid);
514 /* Someone removed the inode. */
515 if (rc == -ENOENT || rc == -ESTALE)
521 if (!scrub->os_partial_scan)
522 scrub->os_full_speed = 1;
524 ops = DTO_INDEX_INSERT;
525 idx = osd_oi_fid2idx(dev, fid);
527 case SCRUB_NEXT_NOLMA:
528 sf->sf_flags |= SF_UPGRADE;
529 if (!(sf->sf_param & SP_DRYRUN)) {
530 rc = osd_ea_fid_set(info, inode, fid, 0, 0);
535 if (!(sf->sf_flags & SF_INCONSISTENT))
536 dev->od_igif_inoi = 0;
538 case SCRUB_NEXT_OSTOBJ:
539 sf->sf_flags |= SF_INCONSISTENT;
540 case SCRUB_NEXT_OSTOBJ_OLD:
543 sf->sf_flags |= SF_RECREATED;
544 if (unlikely(!ldiskfs_test_bit(idx, sf->sf_oi_bitmap)))
545 ldiskfs_set_bit(idx, sf->sf_oi_bitmap);
548 } else if (osd_id_eq(lid, lid2)) {
550 sf->sf_items_updated++;
554 if (!scrub->os_partial_scan)
555 scrub->os_full_speed = 1;
557 sf->sf_flags |= SF_INCONSISTENT;
559 /* XXX: If the device is restored from file-level backup, then
560 * some IGIFs may have been already in OI files, and some
561 * may be not yet. Means upgrading from 1.8 may be partly
562 * processed, but some clients may hold some immobilized
563 * IGIFs, and use them to access related objects. Under
564 * such case, OSD does not know whether an given IGIF has
565 * been processed or to be processed, and it also cannot
566 * generate local ino#/gen# directly from the immobilized
567 * IGIF because of the backup/restore. Then force OSD to
568 * lookup the given IGIF in OI files, and if no entry,
569 * then ask the client to retry after upgrading completed.
570 * No better choice. */
571 dev->od_igif_inoi = 1;
574 rc = osd_scrub_refresh_mapping(info, dev, fid, lid, ops, false,
575 (val == SCRUB_NEXT_OSTOBJ ||
576 val == SCRUB_NEXT_OSTOBJ_OLD) ? OI_KNOWN_ON_OST : 0);
578 if (scrub->os_in_prior)
579 sf->sf_items_updated_prior++;
581 sf->sf_items_updated++;
583 /* The target has been changed, need to be re-loaded. */
584 lu_object_purge(info->oti_env, osd2lu_dev(dev), fid);
591 sf->sf_items_failed++;
592 if (sf->sf_pos_first_inconsistent == 0 ||
593 sf->sf_pos_first_inconsistent > lid->oii_ino)
594 sf->sf_pos_first_inconsistent = lid->oii_ino;
599 /* There may be conflict unlink during the OI scrub,
600 * if happend, then remove the new added OI mapping. */
601 if (ops == DTO_INDEX_INSERT && inode != NULL && !IS_ERR(inode) &&
602 unlikely(inode->i_nlink == 0))
603 osd_scrub_refresh_mapping(info, dev, fid, lid,
604 DTO_INDEX_DELETE, false,
605 (val == SCRUB_NEXT_OSTOBJ ||
606 val == SCRUB_NEXT_OSTOBJ_OLD) ?
607 OI_KNOWN_ON_OST : 0);
608 up_write(&scrub->os_rwsem);
610 if (inode != NULL && !IS_ERR(inode))
614 LASSERT(!list_empty(&oii->oii_list));
616 spin_lock(&scrub->os_lock);
617 list_del_init(&oii->oii_list);
618 spin_unlock(&scrub->os_lock);
621 RETURN(sf->sf_param & SP_FAILOUT ? rc : 0);
626 static int osd_scrub_prep(struct osd_device *dev)
628 struct osd_scrub *scrub = &dev->od_scrub;
629 struct ptlrpc_thread *thread = &scrub->os_thread;
630 struct scrub_file *sf = &scrub->os_file;
631 __u32 flags = scrub->os_start_flags;
633 bool drop_dryrun = false;
636 down_write(&scrub->os_rwsem);
637 if (flags & SS_SET_FAILOUT)
638 sf->sf_param |= SP_FAILOUT;
639 else if (flags & SS_CLEAR_FAILOUT)
640 sf->sf_param &= ~SP_FAILOUT;
642 if (flags & SS_SET_DRYRUN) {
643 sf->sf_param |= SP_DRYRUN;
644 } else if (flags & SS_CLEAR_DRYRUN && sf->sf_param & SP_DRYRUN) {
645 sf->sf_param &= ~SP_DRYRUN;
649 if (flags & SS_RESET)
650 osd_scrub_file_reset(scrub,
651 LDISKFS_SB(osd_sb(dev))->s_es->s_uuid, 0);
653 if (flags & SS_AUTO_FULL) {
654 scrub->os_full_speed = 1;
655 scrub->os_partial_scan = 0;
656 sf->sf_flags |= SF_AUTO;
657 } else if (flags & SS_AUTO_PARTIAL) {
658 scrub->os_full_speed = 0;
659 scrub->os_partial_scan = 1;
660 sf->sf_flags |= SF_AUTO;
661 } else if (sf->sf_flags & (SF_RECREATED | SF_INCONSISTENT |
663 scrub->os_full_speed = 1;
664 scrub->os_partial_scan = 0;
666 scrub->os_full_speed = 0;
667 scrub->os_partial_scan = 0;
670 spin_lock(&scrub->os_lock);
671 scrub->os_in_prior = 0;
672 scrub->os_waiting = 0;
673 scrub->os_paused = 0;
674 scrub->os_in_join = 0;
675 scrub->os_full_scrub = 0;
676 spin_unlock(&scrub->os_lock);
677 scrub->os_new_checked = 0;
678 if (drop_dryrun && sf->sf_pos_first_inconsistent != 0)
679 sf->sf_pos_latest_start = sf->sf_pos_first_inconsistent;
680 else if (sf->sf_pos_last_checkpoint != 0)
681 sf->sf_pos_latest_start = sf->sf_pos_last_checkpoint + 1;
683 sf->sf_pos_latest_start = LDISKFS_FIRST_INO(osd_sb(dev)) + 1;
685 scrub->os_pos_current = sf->sf_pos_latest_start;
686 sf->sf_status = SS_SCANNING;
687 sf->sf_time_latest_start = cfs_time_current_sec();
688 sf->sf_time_last_checkpoint = sf->sf_time_latest_start;
689 rc = osd_scrub_file_store(scrub);
691 spin_lock(&scrub->os_lock);
692 thread_set_flags(thread, SVC_RUNNING);
693 spin_unlock(&scrub->os_lock);
694 wake_up_all(&thread->t_ctl_waitq);
696 up_write(&scrub->os_rwsem);
701 static int osd_scrub_checkpoint(struct osd_scrub *scrub)
703 struct scrub_file *sf = &scrub->os_file;
706 if (likely(cfs_time_before(cfs_time_current(),
707 scrub->os_time_next_checkpoint) ||
708 scrub->os_new_checked == 0))
711 down_write(&scrub->os_rwsem);
712 sf->sf_items_checked += scrub->os_new_checked;
713 scrub->os_new_checked = 0;
714 sf->sf_pos_last_checkpoint = scrub->os_pos_current;
715 sf->sf_time_last_checkpoint = cfs_time_current_sec();
716 sf->sf_run_time += cfs_duration_sec(cfs_time_current() + HALF_SEC -
717 scrub->os_time_last_checkpoint);
718 rc = osd_scrub_file_store(scrub);
719 up_write(&scrub->os_rwsem);
724 static void osd_scrub_post(struct osd_scrub *scrub, int result)
726 struct scrub_file *sf = &scrub->os_file;
729 down_write(&scrub->os_rwsem);
730 spin_lock(&scrub->os_lock);
731 thread_set_flags(&scrub->os_thread, SVC_STOPPING);
732 spin_unlock(&scrub->os_lock);
733 if (scrub->os_new_checked > 0) {
734 sf->sf_items_checked += scrub->os_new_checked;
735 scrub->os_new_checked = 0;
736 sf->sf_pos_last_checkpoint = scrub->os_pos_current;
738 sf->sf_time_last_checkpoint = cfs_time_current_sec();
740 struct osd_device *dev =
741 container_of0(scrub, struct osd_device, od_scrub);
743 dev->od_igif_inoi = 1;
744 dev->od_check_ff = 0;
745 sf->sf_status = SS_COMPLETED;
746 if (!(sf->sf_param & SP_DRYRUN)) {
747 memset(sf->sf_oi_bitmap, 0, SCRUB_OI_BITMAP_SIZE);
748 sf->sf_flags &= ~(SF_RECREATED | SF_INCONSISTENT |
749 SF_UPGRADE | SF_AUTO);
751 sf->sf_time_last_complete = sf->sf_time_last_checkpoint;
752 sf->sf_success_count++;
753 } else if (result == 0) {
754 if (scrub->os_paused)
755 sf->sf_status = SS_PAUSED;
757 sf->sf_status = SS_STOPPED;
759 sf->sf_status = SS_FAILED;
761 sf->sf_run_time += cfs_duration_sec(cfs_time_current() + HALF_SEC -
762 scrub->os_time_last_checkpoint);
763 result = osd_scrub_file_store(scrub);
764 up_write(&scrub->os_rwsem);
769 /* iteration engine */
771 struct osd_iit_param {
772 struct super_block *sb;
773 struct buffer_head *bitmap;
779 typedef int (*osd_iit_next_policy)(struct osd_thread_info *info,
780 struct osd_device *dev,
781 struct osd_iit_param *param,
782 struct osd_idmap_cache **oic,
785 typedef int (*osd_iit_exec_policy)(struct osd_thread_info *info,
786 struct osd_device *dev,
787 struct osd_iit_param *param,
788 struct osd_idmap_cache *oic,
789 bool *noslot, int rc);
791 static int osd_iit_next(struct osd_iit_param *param, __u32 *pos)
793 param->offset = ldiskfs_find_next_bit(param->bitmap->b_data,
794 LDISKFS_INODES_PER_GROUP(param->sb), param->offset);
795 if (param->offset >= LDISKFS_INODES_PER_GROUP(param->sb)) {
796 *pos = 1 + (param->bg+1) * LDISKFS_INODES_PER_GROUP(param->sb);
797 return SCRUB_NEXT_BREAK;
799 *pos = param->gbase + param->offset;
805 * \retval SCRUB_NEXT_OSTOBJ_OLD: FID-on-OST
806 * \retval 0: FID-on-MDT
808 static int osd_scrub_check_local_fldb(struct osd_thread_info *info,
809 struct osd_device *dev,
812 /* XXX: The initial OI scrub will scan the top level /O to generate
813 * a small local FLDB according to the <seq>. If the given FID
814 * is in the local FLDB, then it is FID-on-OST; otherwise it's
815 * quite possible for FID-on-MDT. */
817 return SCRUB_NEXT_OSTOBJ_OLD;
822 static int osd_scrub_get_fid(struct osd_thread_info *info,
823 struct osd_device *dev, struct inode *inode,
824 struct lu_fid *fid, bool scrub)
826 struct lustre_mdt_attrs *lma = &info->oti_mdt_attrs;
828 bool has_lma = false;
830 rc = osd_get_lma(info, inode, &info->oti_obj_dentry, lma);
833 if (lma->lma_compat & LMAC_NOT_IN_OI ||
834 lma->lma_incompat & LMAI_AGENT)
835 return SCRUB_NEXT_CONTINUE;
837 *fid = lma->lma_self_fid;
841 if (lma->lma_compat & LMAC_FID_ON_OST)
842 return SCRUB_NEXT_OSTOBJ;
844 if (fid_is_idif(fid))
845 return SCRUB_NEXT_OSTOBJ_OLD;
847 /* For local object. */
848 if (fid_is_internal(fid))
851 /* For external visible MDT-object with non-normal FID. */
852 if (fid_is_namespace_visible(fid) && !fid_is_norm(fid))
855 /* For the object with normal FID, it may be MDT-object,
856 * or may be 2.4 OST-object, need further distinguish.
857 * Fall through to next section. */
860 if (rc == -ENODATA || rc == 0) {
861 rc = osd_get_idif(info, inode, &info->oti_obj_dentry, fid);
864 /* It is old 2.x (x <= 3) or 1.8 OST-object. */
865 rc = SCRUB_NEXT_OSTOBJ_OLD;
871 /* It is FID-on-OST, but we do not know how
872 * to generate its FID, ignore it directly. */
873 rc = SCRUB_NEXT_CONTINUE;
875 /* It is 2.4 OST-object. */
876 rc = SCRUB_NEXT_OSTOBJ_OLD;
884 if (dev->od_scrub.os_convert_igif) {
885 lu_igif_build(fid, inode->i_ino,
886 inode->i_generation);
888 rc = SCRUB_NEXT_NOLMA;
892 /* It may be FID-on-OST, or may be FID for
893 * non-MDT0, anyway, we do not know how to
894 * generate its FID, ignore it directly. */
895 rc = SCRUB_NEXT_CONTINUE;
900 /* For OI scrub case only: the object has LMA but has no ff
901 * (or ff crashed). It may be MDT-object, may be OST-object
902 * with crashed ff. The last check is local FLDB. */
903 rc = osd_scrub_check_local_fldb(info, dev, fid);
909 static int osd_iit_iget(struct osd_thread_info *info, struct osd_device *dev,
910 struct lu_fid *fid, struct osd_inode_id *lid, __u32 pos,
911 struct super_block *sb, bool scrub)
917 /* Not handle the backend root object and agent parent object.
918 * They are neither visible to namespace nor have OI mappings. */
919 if (unlikely(pos == osd_sb(dev)->s_root->d_inode->i_ino ||
920 pos == osd_remote_parent_ino(dev)))
921 RETURN(SCRUB_NEXT_CONTINUE);
923 osd_id_gen(lid, pos, OSD_OII_NOGEN);
924 inode = osd_iget(info, dev, lid);
927 /* The inode may be removed after bitmap searching, or the
928 * file is new created without inode initialized yet. */
929 if (rc == -ENOENT || rc == -ESTALE)
930 RETURN(SCRUB_NEXT_CONTINUE);
932 CDEBUG(D_LFSCK, "%.16s: fail to read inode, ino# = %u: "
933 "rc = %d\n", LDISKFS_SB(sb)->s_es->s_volume_name,
939 ldiskfs_test_inode_state(inode, LDISKFS_STATE_LUSTRE_NOSCRUB)) {
940 /* Only skip it for the first OI scrub accessing. */
941 ldiskfs_clear_inode_state(inode, LDISKFS_STATE_LUSTRE_NOSCRUB);
942 GOTO(put, rc = SCRUB_NEXT_NOSCRUB);
945 rc = osd_scrub_get_fid(info, dev, inode, fid, scrub);
954 static int osd_scrub_next(struct osd_thread_info *info, struct osd_device *dev,
955 struct osd_iit_param *param,
956 struct osd_idmap_cache **oic, const bool noslot)
958 struct osd_scrub *scrub = &dev->od_scrub;
959 struct ptlrpc_thread *thread = &scrub->os_thread;
961 struct osd_inode_id *lid;
964 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_DELAY) && cfs_fail_val > 0) {
965 struct l_wait_info lwi;
967 lwi = LWI_TIMEOUT(cfs_time_seconds(cfs_fail_val), NULL, NULL);
968 l_wait_event(thread->t_ctl_waitq,
969 !list_empty(&scrub->os_inconsistent_items) ||
970 !thread_is_running(thread),
974 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_CRASH)) {
975 spin_lock(&scrub->os_lock);
976 thread_set_flags(thread, SVC_STOPPING);
977 spin_unlock(&scrub->os_lock);
978 return SCRUB_NEXT_CRASH;
981 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_FATAL))
982 return SCRUB_NEXT_FATAL;
984 if (unlikely(!thread_is_running(thread)))
985 return SCRUB_NEXT_EXIT;
987 if (!list_empty(&scrub->os_inconsistent_items)) {
988 struct osd_inconsistent_item *oii;
990 oii = list_entry(scrub->os_inconsistent_items.next,
991 struct osd_inconsistent_item, oii_list);
992 *oic = &oii->oii_cache;
993 scrub->os_in_prior = 1;
998 return SCRUB_NEXT_WAIT;
1000 rc = osd_iit_next(param, &scrub->os_pos_current);
1004 *oic = &scrub->os_oic;
1005 fid = &(*oic)->oic_fid;
1006 lid = &(*oic)->oic_lid;
1007 rc = osd_iit_iget(info, dev, fid, lid,
1008 scrub->os_pos_current, param->sb, true);
1012 static int osd_preload_next(struct osd_thread_info *info,
1013 struct osd_device *dev, struct osd_iit_param *param,
1014 struct osd_idmap_cache **oic, const bool noslot)
1016 struct osd_otable_cache *ooc = &dev->od_otable_it->ooi_cache;
1017 struct osd_scrub *scrub;
1018 struct ptlrpc_thread *thread;
1021 rc = osd_iit_next(param, &ooc->ooc_pos_preload);
1025 scrub = &dev->od_scrub;
1026 thread = &scrub->os_thread;
1027 if (thread_is_running(thread) &&
1028 ooc->ooc_pos_preload >= scrub->os_pos_current)
1029 return SCRUB_NEXT_EXIT;
1031 rc = osd_iit_iget(info, dev,
1032 &ooc->ooc_cache[ooc->ooc_producer_idx].oic_fid,
1033 &ooc->ooc_cache[ooc->ooc_producer_idx].oic_lid,
1034 ooc->ooc_pos_preload, param->sb, false);
1035 /* If succeed, it needs to move forward; otherwise up layer LFSCK may
1036 * ignore the failure, so it still need to skip the inode next time. */
1037 ooc->ooc_pos_preload = param->gbase + ++(param->offset);
1042 osd_scrub_wakeup(struct osd_scrub *scrub, struct osd_otable_it *it)
1044 spin_lock(&scrub->os_lock);
1045 if (osd_scrub_has_window(scrub, &it->ooi_cache) ||
1046 !list_empty(&scrub->os_inconsistent_items) ||
1047 it->ooi_waiting || !thread_is_running(&scrub->os_thread))
1048 scrub->os_waiting = 0;
1050 scrub->os_waiting = 1;
1051 spin_unlock(&scrub->os_lock);
1053 return !scrub->os_waiting;
1056 static int osd_scrub_exec(struct osd_thread_info *info, struct osd_device *dev,
1057 struct osd_iit_param *param,
1058 struct osd_idmap_cache *oic, bool *noslot, int rc)
1060 struct l_wait_info lwi = { 0 };
1061 struct osd_scrub *scrub = &dev->od_scrub;
1062 struct scrub_file *sf = &scrub->os_file;
1063 struct ptlrpc_thread *thread = &scrub->os_thread;
1064 struct osd_otable_it *it = dev->od_otable_it;
1065 struct osd_otable_cache *ooc = it ? &it->ooi_cache : NULL;
1068 case SCRUB_NEXT_CONTINUE:
1070 case SCRUB_NEXT_WAIT:
1072 case SCRUB_NEXT_NOSCRUB:
1073 down_write(&scrub->os_rwsem);
1074 scrub->os_new_checked++;
1075 sf->sf_items_noscrub++;
1076 up_write(&scrub->os_rwsem);
1080 rc = osd_scrub_check_update(info, dev, oic, rc);
1084 rc = osd_scrub_checkpoint(scrub);
1086 CDEBUG(D_LFSCK, "%.16s: fail to checkpoint, pos = %u: "
1087 "rc = %d\n", osd_scrub2name(scrub),
1088 scrub->os_pos_current, rc);
1089 /* Continue, as long as the scrub itself can go ahead. */
1092 if (scrub->os_in_prior) {
1093 scrub->os_in_prior = 0;
1098 scrub->os_pos_current = param->gbase + ++(param->offset);
1101 if (it != NULL && it->ooi_waiting && ooc != NULL &&
1102 ooc->ooc_pos_preload < scrub->os_pos_current) {
1103 spin_lock(&scrub->os_lock);
1104 it->ooi_waiting = 0;
1105 wake_up_all(&thread->t_ctl_waitq);
1106 spin_unlock(&scrub->os_lock);
1109 if (scrub->os_full_speed || rc == SCRUB_NEXT_CONTINUE)
1112 if (ooc != NULL && osd_scrub_has_window(scrub, ooc)) {
1118 l_wait_event(thread->t_ctl_waitq, osd_scrub_wakeup(scrub, it),
1121 if (ooc != NULL && osd_scrub_has_window(scrub, ooc))
1128 static int osd_preload_exec(struct osd_thread_info *info,
1129 struct osd_device *dev, struct osd_iit_param *param,
1130 struct osd_idmap_cache *oic, bool *noslot, int rc)
1132 struct osd_otable_cache *ooc = &dev->od_otable_it->ooi_cache;
1135 ooc->ooc_cached_items++;
1136 ooc->ooc_producer_idx = (ooc->ooc_producer_idx + 1) &
1137 ~OSD_OTABLE_IT_CACHE_MASK;
1139 return rc > 0 ? 0 : rc;
1142 #define SCRUB_IT_ALL 1
1143 #define SCRUB_IT_CRASH 2
1145 static void osd_scrub_join(struct osd_device *dev, __u32 flags)
1147 struct osd_scrub *scrub = &dev->od_scrub;
1148 struct ptlrpc_thread *thread = &scrub->os_thread;
1149 struct scrub_file *sf = &scrub->os_file;
1153 LASSERT(!(flags & SS_AUTO_PARTIAL));
1155 down_write(&scrub->os_rwsem);
1156 scrub->os_in_join = 1;
1157 if (flags & SS_SET_FAILOUT)
1158 sf->sf_param |= SP_FAILOUT;
1159 else if (flags & SS_CLEAR_FAILOUT)
1160 sf->sf_param &= ~SP_FAILOUT;
1162 if (flags & SS_SET_DRYRUN)
1163 sf->sf_param |= SP_DRYRUN;
1164 else if (flags & SS_CLEAR_DRYRUN)
1165 sf->sf_param &= ~SP_DRYRUN;
1167 if (flags & SS_RESET)
1168 osd_scrub_file_reset(scrub,
1169 LDISKFS_SB(osd_sb(dev))->s_es->s_uuid, 0);
1171 if (flags & SS_AUTO_FULL ||
1172 sf->sf_flags & (SF_RECREATED | SF_INCONSISTENT | SF_UPGRADE))
1173 scrub->os_full_speed = 1;
1175 scrub->os_full_speed = 0;
1177 scrub->os_new_checked = 0;
1178 if (sf->sf_pos_last_checkpoint != 0)
1179 sf->sf_pos_latest_start = sf->sf_pos_last_checkpoint + 1;
1181 sf->sf_pos_latest_start = LDISKFS_FIRST_INO(osd_sb(dev)) + 1;
1183 scrub->os_pos_current = sf->sf_pos_latest_start;
1184 sf->sf_time_latest_start = cfs_time_current_sec();
1185 sf->sf_time_last_checkpoint = sf->sf_time_latest_start;
1186 rc = osd_scrub_file_store(scrub);
1188 CDEBUG(D_LFSCK, "%.16s: fail to store scrub file when join "
1189 "the OI scrub: rc = %d\n", osd_scrub2name(scrub), rc);
1191 spin_lock(&scrub->os_lock);
1192 scrub->os_waiting = 0;
1193 scrub->os_paused = 0;
1194 scrub->os_partial_scan = 0;
1195 scrub->os_in_join = 0;
1196 scrub->os_full_scrub = 0;
1197 spin_unlock(&scrub->os_lock);
1198 wake_up_all(&thread->t_ctl_waitq);
1199 up_write(&scrub->os_rwsem);
1204 static int osd_inode_iteration(struct osd_thread_info *info,
1205 struct osd_device *dev, __u32 max, bool preload)
1207 struct osd_scrub *scrub = &dev->od_scrub;
1208 struct ptlrpc_thread *thread = &scrub->os_thread;
1209 struct scrub_file *sf = &scrub->os_file;
1210 osd_iit_next_policy next;
1211 osd_iit_exec_policy exec;
1214 struct osd_iit_param param = { 0 };
1215 struct l_wait_info lwi = { 0 };
1221 param.sb = osd_sb(dev);
1225 while (scrub->os_partial_scan && !scrub->os_in_join) {
1226 struct osd_idmap_cache *oic = NULL;
1228 rc = osd_scrub_next(info, dev, ¶m, &oic, noslot);
1230 case SCRUB_NEXT_EXIT:
1232 case SCRUB_NEXT_CRASH:
1233 RETURN(SCRUB_IT_CRASH);
1234 case SCRUB_NEXT_FATAL:
1236 case SCRUB_NEXT_WAIT: {
1237 struct kstatfs *ksfs = &info->oti_ksfs;
1240 if (dev->od_full_scrub_ratio == OFSR_NEVER ||
1241 unlikely(sf->sf_items_updated_prior == 0))
1244 if (dev->od_full_scrub_ratio == OFSR_DIRECTLY ||
1245 scrub->os_full_scrub) {
1246 osd_scrub_join(dev, SS_AUTO_FULL | SS_RESET);
1250 rc = param.sb->s_op->statfs(param.sb->s_root, ksfs);
1254 used = ksfs->f_files - ksfs->f_ffree;
1255 do_div(used, sf->sf_items_updated_prior);
1256 /* If we hit too much inconsistent OI mappings during
1257 * the partial scan, then scan the device completely. */
1258 if (used < dev->od_full_scrub_ratio) {
1259 osd_scrub_join(dev, SS_AUTO_FULL | SS_RESET);
1264 if (OBD_FAIL_CHECK(OBD_FAIL_OSD_SCRUB_DELAY) &&
1268 sf->sf_status = SS_COMPLETED;
1269 sf->sf_flags &= ~(SF_RECREATED | SF_INCONSISTENT |
1270 SF_UPGRADE | SF_AUTO);
1271 l_wait_event(thread->t_ctl_waitq,
1272 !thread_is_running(thread) ||
1273 !scrub->os_partial_scan ||
1274 scrub->os_in_join ||
1275 !list_empty(&scrub->os_inconsistent_items),
1278 if (unlikely(!thread_is_running(thread)))
1281 if (!scrub->os_partial_scan || scrub->os_in_join)
1287 LASSERTF(rc == 0, "rc = %d\n", rc);
1289 sf->sf_status = SS_SCANNING;
1290 sf->sf_flags |= SF_AUTO;
1291 osd_scrub_exec(info, dev, ¶m, oic, &noslot, rc);
1298 sf->sf_status = SS_SCANNING;
1299 l_wait_event(thread->t_ctl_waitq,
1300 !thread_is_running(thread) || !scrub->os_in_join,
1303 if (unlikely(!thread_is_running(thread)))
1309 next = osd_scrub_next;
1310 exec = osd_scrub_exec;
1311 pos = &scrub->os_pos_current;
1312 count = &scrub->os_new_checked;
1314 struct osd_otable_cache *ooc = &dev->od_otable_it->ooi_cache;
1316 next = osd_preload_next;
1317 exec = osd_preload_exec;
1318 pos = &ooc->ooc_pos_preload;
1319 count = &ooc->ooc_cached_items;
1321 limit = le32_to_cpu(LDISKFS_SB(param.sb)->s_es->s_inodes_count);
1323 while (*pos <= limit && *count < max) {
1324 struct osd_idmap_cache *oic = NULL;
1325 struct ldiskfs_group_desc *desc;
1327 param.bg = (*pos - 1) / LDISKFS_INODES_PER_GROUP(param.sb);
1328 desc = ldiskfs_get_group_desc(param.sb, param.bg, NULL);
1332 ldiskfs_lock_group(param.sb, param.bg);
1333 if (desc->bg_flags & cpu_to_le16(LDISKFS_BG_INODE_UNINIT)) {
1334 ldiskfs_unlock_group(param.sb, param.bg);
1335 *pos = 1 + (param.bg + 1) *
1336 LDISKFS_INODES_PER_GROUP(param.sb);
1339 ldiskfs_unlock_group(param.sb, param.bg);
1341 param.offset = (*pos - 1) % LDISKFS_INODES_PER_GROUP(param.sb);
1342 param.gbase = 1 + param.bg * LDISKFS_INODES_PER_GROUP(param.sb);
1343 param.bitmap = ldiskfs_read_inode_bitmap(param.sb, param.bg);
1344 if (param.bitmap == NULL) {
1345 CDEBUG(D_LFSCK, "%.16s: fail to read bitmap for %u, "
1346 "scrub will stop, urgent mode\n",
1347 osd_scrub2name(scrub), (__u32)param.bg);
1351 while (param.offset < LDISKFS_INODES_PER_GROUP(param.sb) &&
1354 ldiskfs_itable_unused_count(param.sb, desc) >
1355 LDISKFS_INODES_PER_GROUP(param.sb))
1358 rc = next(info, dev, ¶m, &oic, noslot);
1360 case SCRUB_NEXT_BREAK:
1362 case SCRUB_NEXT_EXIT:
1363 brelse(param.bitmap);
1365 case SCRUB_NEXT_CRASH:
1366 brelse(param.bitmap);
1367 RETURN(SCRUB_IT_CRASH);
1368 case SCRUB_NEXT_FATAL:
1369 brelse(param.bitmap);
1373 rc = exec(info, dev, ¶m, oic, &noslot, rc);
1375 brelse(param.bitmap);
1381 brelse(param.bitmap);
1385 RETURN(SCRUB_IT_ALL);
1389 static int osd_otable_it_preload(const struct lu_env *env,
1390 struct osd_otable_it *it)
1392 struct osd_device *dev = it->ooi_dev;
1393 struct osd_scrub *scrub = &dev->od_scrub;
1394 struct osd_otable_cache *ooc = &it->ooi_cache;
1398 rc = osd_inode_iteration(osd_oti_get(env), dev,
1399 OSD_OTABLE_IT_CACHE_SIZE, true);
1400 if (rc == SCRUB_IT_ALL)
1401 it->ooi_all_cached = 1;
1403 if (scrub->os_waiting && osd_scrub_has_window(scrub, ooc)) {
1404 spin_lock(&scrub->os_lock);
1405 scrub->os_waiting = 0;
1406 wake_up_all(&scrub->os_thread.t_ctl_waitq);
1407 spin_unlock(&scrub->os_lock);
1410 RETURN(rc < 0 ? rc : ooc->ooc_cached_items);
1413 static int osd_scrub_main(void *args)
1416 struct osd_device *dev = (struct osd_device *)args;
1417 struct osd_scrub *scrub = &dev->od_scrub;
1418 struct ptlrpc_thread *thread = &scrub->os_thread;
1422 rc = lu_env_init(&env, LCT_LOCAL);
1424 CDEBUG(D_LFSCK, "%.16s: OI scrub fail to init env: rc = %d\n",
1425 osd_scrub2name(scrub), rc);
1429 rc = osd_scrub_prep(dev);
1431 CDEBUG(D_LFSCK, "%.16s: OI scrub fail to scrub prep: rc = %d\n",
1432 osd_scrub2name(scrub), rc);
1436 if (!scrub->os_full_speed && !scrub->os_partial_scan) {
1437 struct l_wait_info lwi = { 0 };
1438 struct osd_otable_it *it = dev->od_otable_it;
1439 struct osd_otable_cache *ooc = &it->ooi_cache;
1441 l_wait_event(thread->t_ctl_waitq,
1442 it->ooi_user_ready || !thread_is_running(thread),
1444 if (unlikely(!thread_is_running(thread)))
1447 scrub->os_pos_current = ooc->ooc_pos_preload;
1450 CDEBUG(D_LFSCK, "%.16s: OI scrub start, flags = 0x%x, pos = %u\n",
1451 osd_scrub2name(scrub), scrub->os_start_flags,
1452 scrub->os_pos_current);
1454 rc = osd_inode_iteration(osd_oti_get(&env), dev, ~0U, false);
1455 if (unlikely(rc == SCRUB_IT_CRASH))
1456 GOTO(out, rc = -EINVAL);
1460 osd_scrub_post(scrub, rc);
1461 CDEBUG(D_LFSCK, "%.16s: OI scrub: stop, pos = %u: rc = %d\n",
1462 osd_scrub2name(scrub), scrub->os_pos_current, rc);
1465 while (!list_empty(&scrub->os_inconsistent_items)) {
1466 struct osd_inconsistent_item *oii;
1468 oii = list_entry(scrub->os_inconsistent_items.next,
1469 struct osd_inconsistent_item, oii_list);
1470 list_del_init(&oii->oii_list);
1476 spin_lock(&scrub->os_lock);
1477 thread_set_flags(thread, SVC_STOPPED);
1478 wake_up_all(&thread->t_ctl_waitq);
1479 spin_unlock(&scrub->os_lock);
1483 /* initial OI scrub */
1485 typedef int (*scandir_t)(struct osd_thread_info *, struct osd_device *,
1486 struct dentry *, filldir_t filldir);
1488 static int osd_ios_varfid_fill(void *buf, const char *name, int namelen,
1489 loff_t offset, __u64 ino, unsigned d_type);
1490 static int osd_ios_lf_fill(void *buf, const char *name, int namelen,
1491 loff_t offset, __u64 ino, unsigned d_type);
1492 static int osd_ios_dl_fill(void *buf, const char *name, int namelen,
1493 loff_t offset, __u64 ino, unsigned d_type);
1496 osd_ios_general_scan(struct osd_thread_info *info, struct osd_device *dev,
1497 struct dentry *dentry, filldir_t filldir);
1499 osd_ios_ROOT_scan(struct osd_thread_info *info, struct osd_device *dev,
1500 struct dentry *dentry, filldir_t filldir);
1503 osd_ios_OBJECTS_scan(struct osd_thread_info *info, struct osd_device *dev,
1504 struct dentry *dentry, filldir_t filldir);
1507 OLF_SCAN_SUBITEMS = 0x0001,
1508 OLF_HIDE_FID = 0x0002,
1509 OLF_SHOW_NAME = 0x0004,
1515 struct lu_fid olm_fid;
1517 scandir_t olm_scandir;
1518 filldir_t olm_filldir;
1521 /* Add the new introduced local files in the list in the future. */
1522 static const struct osd_lf_map osd_lf_maps[] = {
1524 { CATLIST, { FID_SEQ_LOCAL_FILE, LLOG_CATALOGS_OID, 0 }, OLF_SHOW_NAME,
1528 { MOUNT_CONFIGS_DIR, { FID_SEQ_LOCAL_FILE, MGS_CONFIGS_OID, 0 },
1529 OLF_SCAN_SUBITEMS, osd_ios_general_scan,
1530 osd_ios_varfid_fill },
1532 /* NIDTBL_VERSIONS */
1533 { MGS_NIDTBL_DIR, { 0, 0, 0 }, OLF_SCAN_SUBITEMS,
1534 osd_ios_general_scan, osd_ios_varfid_fill },
1537 { "PENDING", { 0, 0, 0 }, 0, NULL, NULL },
1540 { "ROOT", { FID_SEQ_ROOT, 1, 0 },
1541 OLF_SCAN_SUBITEMS | OLF_HIDE_FID, osd_ios_ROOT_scan, NULL },
1543 /* changelog_catalog */
1544 { CHANGELOG_CATALOG, { 0, 0, 0 }, 0, NULL, NULL },
1546 /* changelog_users */
1547 { CHANGELOG_USERS, { 0, 0, 0 }, 0, NULL, NULL },
1550 { "fld", { FID_SEQ_LOCAL_FILE, FLD_INDEX_OID, 0 }, OLF_SHOW_NAME,
1554 { LAST_RCVD, { FID_SEQ_LOCAL_FILE, LAST_RECV_OID, 0 }, OLF_SHOW_NAME,
1557 /* lfsck_bookmark */
1558 { "lfsck_bookmark", { 0, 0, 0 }, 0, NULL, NULL },
1561 { LOV_OBJID, { FID_SEQ_LOCAL_FILE, MDD_LOV_OBJ_OID, 0 }, OLF_SHOW_NAME,
1565 { LOV_OBJSEQ, { FID_SEQ_LOCAL_FILE, MDD_LOV_OBJ_OSEQ, 0 },
1566 OLF_SHOW_NAME, NULL, NULL },
1569 { QMT_DIR, { 0, 0, 0 }, OLF_SCAN_SUBITEMS,
1570 osd_ios_general_scan, osd_ios_varfid_fill },
1573 { QSD_DIR, { 0, 0, 0 }, OLF_SCAN_SUBITEMS,
1574 osd_ios_general_scan, osd_ios_varfid_fill },
1577 { "seq_ctl", { FID_SEQ_LOCAL_FILE, FID_SEQ_CTL_OID, 0 },
1578 OLF_SHOW_NAME, NULL, NULL },
1581 { "seq_srv", { FID_SEQ_LOCAL_FILE, FID_SEQ_SRV_OID, 0 },
1582 OLF_SHOW_NAME, NULL, NULL },
1585 { HEALTH_CHECK, { FID_SEQ_LOCAL_FILE, OFD_HEALTH_CHECK_OID, 0 },
1586 OLF_SHOW_NAME, NULL, NULL },
1588 /* lfsck_namespace */
1589 { "lfsck_namespace", { 0, 0, 0 }, 0, NULL, NULL },
1591 /* OBJECTS, upgrade from old device */
1592 { OBJECTS, { 0, 0, 0 }, OLF_SCAN_SUBITEMS, osd_ios_OBJECTS_scan, NULL },
1594 /* lquota_v2.user, upgrade from old device */
1595 { "lquota_v2.user", { 0, 0, 0 }, 0, NULL, NULL },
1597 /* lquota_v2.group, upgrade from old device */
1598 { "lquota_v2.group", { 0, 0, 0 }, 0, NULL, NULL },
1600 /* LAST_GROUP, upgrade from old device */
1601 { "LAST_GROUP", { FID_SEQ_LOCAL_FILE, OFD_LAST_GROUP_OID, 0 },
1602 OLF_SHOW_NAME, NULL, NULL },
1604 /* SLAVE_LOG, llog for destroy slave stripes of striped dir */
1605 { "SLAVE_LOG", { FID_SEQ_LOCAL_FILE, SLAVE_LLOG_CATALOGS_OID, 0 },
1606 OLF_SHOW_NAME, NULL, NULL },
1609 { "lost+found", { FID_SEQ_LOCAL_FILE, OSD_LPF_OID, 0 },
1610 OLF_SCAN_SUBITEMS, osd_ios_general_scan, osd_ios_lf_fill },
1612 { NULL, { 0, 0, 0 }, 0, NULL, NULL }
1615 /* Add the new introduced files under .lustre/ in the list in the future. */
1616 static const struct osd_lf_map osd_dl_maps[] = {
1618 { "fid", { FID_SEQ_DOT_LUSTRE, FID_OID_DOT_LUSTRE_OBF, 0 }, 0,
1621 /* .lustre/lost+found */
1622 { "lost+found", { FID_SEQ_DOT_LUSTRE, FID_OID_DOT_LUSTRE_LPF, 0 }, 0,
1625 { NULL, { 0, 0, 0 }, 0, NULL, NULL }
1628 struct osd_ios_item {
1629 struct list_head oii_list;
1630 struct dentry *oii_dentry;
1631 scandir_t oii_scandir;
1632 filldir_t oii_filldir;
1635 struct osd_ios_filldir_buf {
1636 #ifdef HAVE_DIR_CONTEXT
1637 /* please keep it as first member */
1638 struct dir_context ctx;
1640 struct osd_thread_info *oifb_info;
1641 struct osd_device *oifb_dev;
1642 struct dentry *oifb_dentry;
1645 static inline struct dentry *
1646 osd_ios_lookup_one_len(const char *name, struct dentry *parent, int namelen)
1648 struct dentry *dentry;
1650 dentry = ll_lookup_one_len(name, parent, namelen);
1651 if (!IS_ERR(dentry) && dentry->d_inode == NULL) {
1653 return ERR_PTR(-ENOENT);
1660 osd_ios_new_item(struct osd_device *dev, struct dentry *dentry,
1661 scandir_t scandir, filldir_t filldir)
1663 struct osd_ios_item *item;
1666 OBD_ALLOC_PTR(item);
1670 INIT_LIST_HEAD(&item->oii_list);
1671 item->oii_dentry = dget(dentry);
1672 item->oii_scandir = scandir;
1673 item->oii_filldir = filldir;
1674 list_add_tail(&item->oii_list, &dev->od_ios_list);
1680 * osd_ios_scan_one() - check/fix LMA FID and OI entry for one inode
1682 * The passed \a inode's \a fid is verified against the LMA FID. If the \a fid
1683 * is NULL or is empty the IGIF FID is used. The FID is verified in the OI to
1684 * reference the inode, or fixed if it is missing or references another inode.
1687 osd_ios_scan_one(struct osd_thread_info *info, struct osd_device *dev,
1688 struct inode *inode, const struct lu_fid *fid, int flags)
1690 struct lustre_mdt_attrs *lma = &info->oti_mdt_attrs;
1691 struct osd_inode_id *id = &info->oti_id;
1692 struct osd_inode_id *id2 = &info->oti_id2;
1693 struct osd_scrub *scrub = &dev->od_scrub;
1694 struct scrub_file *sf = &scrub->os_file;
1699 rc = osd_get_lma(info, inode, &info->oti_obj_dentry, lma);
1700 if (rc != 0 && rc != -ENODATA) {
1701 CDEBUG(D_LFSCK, "%s: fail to get lma for init OI scrub: "
1702 "rc = %d\n", osd_name(dev), rc);
1707 osd_id_gen(id, inode->i_ino, inode->i_generation);
1708 if (rc == -ENODATA) {
1709 if (fid == NULL || fid_is_zero(fid) || flags & OLF_HIDE_FID)
1710 lu_igif_build(&tfid, inode->i_ino, inode->i_generation);
1713 rc = osd_ea_fid_set(info, inode, &tfid, 0, 0);
1715 CDEBUG(D_LFSCK, "%s: fail to set LMA for init OI "
1716 "scrub: rc = %d\n", osd_name(dev), rc);
1721 if (lma->lma_compat & LMAC_NOT_IN_OI)
1724 tfid = lma->lma_self_fid;
1727 rc = osd_oi_lookup(info, dev, &tfid, id2, 0);
1732 rc = osd_scrub_refresh_mapping(info, dev, &tfid, id,
1733 DTO_INDEX_INSERT, true, 0);
1740 if (osd_id_eq_strict(id, id2))
1743 if (!(sf->sf_flags & SF_INCONSISTENT)) {
1744 osd_scrub_file_reset(scrub,
1745 LDISKFS_SB(osd_sb(dev))->s_es->s_uuid,
1747 rc = osd_scrub_file_store(scrub);
1752 rc = osd_scrub_refresh_mapping(info, dev, &tfid, id,
1753 DTO_INDEX_UPDATE, true, 0);
1761 * It scans the /lost+found, and for the OST-object (with filter_fid
1762 * or filter_fid_old), move them back to its proper /O/<seq>/d<x>.
1764 static int osd_ios_lf_fill(void *buf, const char *name, int namelen,
1765 loff_t offset, __u64 ino, unsigned d_type)
1767 struct osd_ios_filldir_buf *fill_buf = buf;
1768 struct osd_thread_info *info = fill_buf->oifb_info;
1769 struct osd_device *dev = fill_buf->oifb_dev;
1770 struct lu_fid *fid = &info->oti_fid;
1771 struct osd_scrub *scrub = &dev->od_scrub;
1772 struct dentry *parent = fill_buf->oifb_dentry;
1773 struct dentry *child;
1774 struct inode *dir = parent->d_inode;
1775 struct inode *inode;
1779 /* skip any '.' started names */
1783 scrub->os_lf_scanned++;
1784 child = osd_ios_lookup_one_len(name, parent, namelen);
1785 if (IS_ERR(child)) {
1786 CDEBUG(D_LFSCK, "%s: cannot lookup child '%.*s': rc = %d\n",
1787 osd_name(dev), namelen, name, (int)PTR_ERR(child));
1791 inode = child->d_inode;
1792 if (S_ISDIR(inode->i_mode)) {
1793 rc = osd_ios_new_item(dev, child, osd_ios_general_scan,
1796 CDEBUG(D_LFSCK, "%s: cannot add child '%.*s': "
1797 "rc = %d\n", osd_name(dev), namelen, name, rc);
1801 if (!S_ISREG(inode->i_mode))
1804 rc = osd_scrub_get_fid(info, dev, inode, fid, true);
1805 if (rc == SCRUB_NEXT_OSTOBJ || rc == SCRUB_NEXT_OSTOBJ_OLD) {
1806 rc = osd_obj_map_recover(info, dev, dir, child, fid);
1808 CDEBUG(D_LFSCK, "recovered '%.*s' ["DFID"] from "
1809 "/lost+found.\n", namelen, name, PFID(fid));
1810 scrub->os_lf_repaired++;
1812 CDEBUG(D_LFSCK, "%s: cannot rename for '%.*s' "
1814 osd_name(dev), namelen, name, PFID(fid), rc);
1818 /* XXX: For MDT-objects, we can move them from /lost+found to namespace
1819 * visible place, such as the /ROOT/.lustre/lost+found, then LFSCK
1820 * can process them in furtuer. */
1826 scrub->os_lf_failed++;
1828 /* skip the failure to make the scanning to continue. */
1832 static int osd_ios_varfid_fill(void *buf, const char *name, int namelen,
1833 loff_t offset, __u64 ino, unsigned d_type)
1835 struct osd_ios_filldir_buf *fill_buf = buf;
1836 struct osd_device *dev = fill_buf->oifb_dev;
1837 struct dentry *child;
1841 /* skip any '.' started names */
1845 child = osd_ios_lookup_one_len(name, fill_buf->oifb_dentry, namelen);
1847 RETURN(PTR_ERR(child));
1849 rc = osd_ios_scan_one(fill_buf->oifb_info, dev, child->d_inode,
1851 if (rc == 0 && S_ISDIR(child->d_inode->i_mode))
1852 rc = osd_ios_new_item(dev, child, osd_ios_general_scan,
1853 osd_ios_varfid_fill);
1859 static int osd_ios_dl_fill(void *buf, const char *name, int namelen,
1860 loff_t offset, __u64 ino, unsigned d_type)
1862 struct osd_ios_filldir_buf *fill_buf = buf;
1863 struct osd_device *dev = fill_buf->oifb_dev;
1864 const struct osd_lf_map *map;
1865 struct dentry *child;
1869 /* skip any '.' started names */
1873 for (map = osd_dl_maps; map->olm_name != NULL; map++) {
1874 if (strlen(map->olm_name) != namelen)
1877 if (strncmp(map->olm_name, name, namelen) == 0)
1881 if (map->olm_name == NULL)
1884 child = osd_ios_lookup_one_len(name, fill_buf->oifb_dentry, namelen);
1886 RETURN(PTR_ERR(child));
1888 rc = osd_ios_scan_one(fill_buf->oifb_info, dev, child->d_inode,
1889 &map->olm_fid, map->olm_flags);
1895 static int osd_ios_root_fill(void *buf, const char *name, int namelen,
1896 loff_t offset, __u64 ino, unsigned d_type)
1898 struct osd_ios_filldir_buf *fill_buf = buf;
1899 struct osd_device *dev = fill_buf->oifb_dev;
1900 const struct osd_lf_map *map;
1901 struct dentry *child;
1905 /* skip any '.' started names */
1909 for (map = osd_lf_maps; map->olm_name != NULL; map++) {
1910 if (strlen(map->olm_name) != namelen)
1913 if (strncmp(map->olm_name, name, namelen) == 0)
1917 if (map->olm_name == NULL)
1920 child = osd_ios_lookup_one_len(name, fill_buf->oifb_dentry, namelen);
1922 RETURN(PTR_ERR(child));
1924 if (!(map->olm_flags & OLF_NO_OI))
1925 rc = osd_ios_scan_one(fill_buf->oifb_info, dev, child->d_inode,
1926 &map->olm_fid, map->olm_flags);
1927 if (rc == 0 && map->olm_flags & OLF_SCAN_SUBITEMS)
1928 rc = osd_ios_new_item(dev, child, map->olm_scandir,
1936 osd_ios_general_scan(struct osd_thread_info *info, struct osd_device *dev,
1937 struct dentry *dentry, filldir_t filldir)
1939 struct osd_ios_filldir_buf buf = {
1940 #ifdef HAVE_DIR_CONTEXT
1941 .ctx.actor = filldir,
1945 .oifb_dentry = dentry };
1946 struct file *filp = &info->oti_it_ea.oie_file;
1947 struct inode *inode = dentry->d_inode;
1948 const struct file_operations *fops = inode->i_fop;
1952 LASSERT(filldir != NULL);
1955 filp->f_dentry = dentry;
1956 filp->f_mode = FMODE_64BITHASH;
1957 filp->f_mapping = inode->i_mapping;
1959 filp->private_data = NULL;
1960 set_file_inode(filp, inode);
1962 #ifdef HAVE_DIR_CONTEXT
1963 buf.ctx.pos = filp->f_pos;
1964 rc = fops->iterate(filp, &buf.ctx);
1965 filp->f_pos = buf.ctx.pos;
1967 rc = fops->readdir(filp, &buf, filldir);
1969 fops->release(inode, filp);
1975 osd_ios_ROOT_scan(struct osd_thread_info *info, struct osd_device *dev,
1976 struct dentry *dentry, filldir_t filldir)
1978 struct osd_scrub *scrub = &dev->od_scrub;
1979 struct scrub_file *sf = &scrub->os_file;
1980 struct dentry *child;
1984 /* It is existing MDT0 device. We only allow the case of object without
1985 * LMA to happen on the MDT0, which is usually for old 1.8 MDT. Then we
1986 * can generate IGIF mode FID for the object and related OI mapping. If
1987 * it is on other MDTs, then becuase file-level backup/restore, related
1988 * OI mapping may be invalid already, we do not know which is the right
1989 * FID for the object. We only allow IGIF objects to reside on the MDT0.
1991 * XXX: For the case of object on non-MDT0 device with neither LMA nor
1992 * "fid" xattr, then something crashed. We cannot re-generate the
1993 * FID directly, instead, the OI scrub will scan the OI structure
1994 * and try to re-generate the LMA from the OI mapping. But if the
1995 * OI mapping crashed or lost also, then we have to give up under
1996 * double failure cases. */
1997 scrub->os_convert_igif = 1;
1998 child = osd_ios_lookup_one_len(dot_lustre_name, dentry,
1999 strlen(dot_lustre_name));
2000 if (IS_ERR(child)) {
2001 rc = PTR_ERR(child);
2002 if (rc == -ENOENT) {
2003 /* It is 1.8 MDT device. */
2004 if (!(sf->sf_flags & SF_UPGRADE)) {
2005 osd_scrub_file_reset(scrub,
2006 LDISKFS_SB(osd_sb(dev))->s_es->s_uuid,
2008 sf->sf_internal_flags &= ~SIF_NO_HANDLE_OLD_FID;
2009 rc = osd_scrub_file_store(scrub);
2015 /* For lustre-2.x (x <= 3), the ".lustre" has NO FID-in-LMA,
2016 * so the client will get IGIF for the ".lustre" object when
2019 * From the OI scrub view, when the MDT upgrade to Lustre-2.4,
2020 * it does not know whether there are some old clients cached
2021 * the ".lustre" IGIF during the upgrading. Two choices:
2023 * 1) Generate IGIF-in-LMA and IGIF-in-OI for the ".lustre".
2024 * It will allow the old connected clients to access the
2025 * ".lustre" with cached IGIF. But it will cause others
2026 * on the MDT failed to check "fid_is_dot_lustre()".
2028 * 2) Use fixed FID {FID_SEQ_DOT_LUSTRE, FID_OID_DOT_LUSTRE, 0}
2029 * for ".lustre" in spite of whether there are some clients
2030 * cached the ".lustre" IGIF or not. It enables the check
2031 * "fid_is_dot_lustre()" on the MDT, although it will cause
2032 * that the old connected clients cannot access the ".lustre"
2033 * with the cached IGIF.
2035 * Usually, it is rare case for the old connected clients
2036 * to access the ".lustre" with cached IGIF. So we prefer
2037 * to the solution 2). */
2038 rc = osd_ios_scan_one(info, dev, child->d_inode,
2039 &LU_DOT_LUSTRE_FID, 0);
2041 rc = osd_ios_new_item(dev, child, osd_ios_general_scan,
2050 osd_ios_OBJECTS_scan(struct osd_thread_info *info, struct osd_device *dev,
2051 struct dentry *dentry, filldir_t filldir)
2053 struct osd_scrub *scrub = &dev->od_scrub;
2054 struct scrub_file *sf = &scrub->os_file;
2055 struct dentry *child;
2059 if (unlikely(sf->sf_internal_flags & SIF_NO_HANDLE_OLD_FID)) {
2060 sf->sf_internal_flags &= ~SIF_NO_HANDLE_OLD_FID;
2061 rc = osd_scrub_file_store(scrub);
2066 child = osd_ios_lookup_one_len(ADMIN_USR, dentry, strlen(ADMIN_USR));
2067 if (!IS_ERR(child)) {
2068 rc = osd_ios_scan_one(info, dev, child->d_inode, NULL, 0);
2071 rc = PTR_ERR(child);
2074 if (rc != 0 && rc != -ENOENT)
2077 child = osd_ios_lookup_one_len(ADMIN_GRP, dentry, strlen(ADMIN_GRP));
2078 if (!IS_ERR(child)) {
2079 rc = osd_ios_scan_one(info, dev, child->d_inode, NULL, 0);
2082 rc = PTR_ERR(child);
2091 static int osd_initial_OI_scrub(struct osd_thread_info *info,
2092 struct osd_device *dev)
2094 struct osd_ios_item *item = NULL;
2095 scandir_t scandir = osd_ios_general_scan;
2096 filldir_t filldir = osd_ios_root_fill;
2097 struct dentry *dentry = osd_sb(dev)->s_root;
2098 const struct osd_lf_map *map = osd_lf_maps;
2102 /* Lookup IGIF in OI by force for initial OI scrub. */
2103 dev->od_igif_inoi = 1;
2106 rc = scandir(info, dev, dentry, filldir);
2108 dput(item->oii_dentry);
2115 if (list_empty(&dev->od_ios_list))
2118 item = list_entry(dev->od_ios_list.next,
2119 struct osd_ios_item, oii_list);
2120 list_del_init(&item->oii_list);
2122 LASSERT(item->oii_scandir != NULL);
2123 scandir = item->oii_scandir;
2124 filldir = item->oii_filldir;
2125 dentry = item->oii_dentry;
2128 while (!list_empty(&dev->od_ios_list)) {
2129 item = list_entry(dev->od_ios_list.next,
2130 struct osd_ios_item, oii_list);
2131 list_del_init(&item->oii_list);
2132 dput(item->oii_dentry);
2139 /* There maybe the case that the object has been removed, but its OI
2140 * mapping is still in the OI file, such as the "CATALOGS" after MDT
2141 * file-level backup/restore. So here cleanup the stale OI mappings. */
2142 while (map->olm_name != NULL) {
2143 struct dentry *child;
2145 if (fid_is_zero(&map->olm_fid)) {
2150 child = osd_ios_lookup_one_len(map->olm_name,
2151 osd_sb(dev)->s_root,
2152 strlen(map->olm_name));
2155 else if (PTR_ERR(child) == -ENOENT)
2156 osd_scrub_refresh_mapping(info, dev, &map->olm_fid,
2157 NULL, DTO_INDEX_DELETE,
2165 char *osd_lf_fid2name(const struct lu_fid *fid)
2167 const struct osd_lf_map *map = osd_lf_maps;
2169 while (map->olm_name != NULL) {
2170 if (!lu_fid_eq(fid, &map->olm_fid)) {
2175 if (map->olm_flags & OLF_SHOW_NAME)
2176 return map->olm_name;
2184 /* OI scrub start/stop */
2186 static int do_osd_scrub_start(struct osd_device *dev, __u32 flags)
2188 struct osd_scrub *scrub = &dev->od_scrub;
2189 struct ptlrpc_thread *thread = &scrub->os_thread;
2190 struct l_wait_info lwi = { 0 };
2191 struct task_struct *task;
2195 /* os_lock: sync status between stop and scrub thread */
2196 spin_lock(&scrub->os_lock);
2199 if (thread_is_running(thread)) {
2200 spin_unlock(&scrub->os_lock);
2201 if (!scrub->os_partial_scan || flags & SS_AUTO_PARTIAL)
2204 osd_scrub_join(dev, flags);
2205 spin_lock(&scrub->os_lock);
2206 if (!thread_is_running(thread))
2209 spin_unlock(&scrub->os_lock);
2213 if (unlikely(thread_is_stopping(thread))) {
2214 spin_unlock(&scrub->os_lock);
2215 l_wait_event(thread->t_ctl_waitq,
2216 thread_is_stopped(thread),
2218 spin_lock(&scrub->os_lock);
2221 spin_unlock(&scrub->os_lock);
2223 if (scrub->os_file.sf_status == SS_COMPLETED) {
2224 if (!(flags & SS_SET_FAILOUT))
2225 flags |= SS_CLEAR_FAILOUT;
2227 if (!(flags & SS_SET_DRYRUN))
2228 flags |= SS_CLEAR_DRYRUN;
2233 scrub->os_start_flags = flags;
2234 thread_set_flags(thread, 0);
2235 task = kthread_run(osd_scrub_main, dev, "OI_scrub");
2238 CERROR("%.16s: cannot start iteration thread: rc = %d\n",
2239 osd_scrub2name(scrub), rc);
2243 l_wait_event(thread->t_ctl_waitq,
2244 thread_is_running(thread) || thread_is_stopped(thread),
2250 int osd_scrub_start(struct osd_device *dev, __u32 flags)
2255 /* od_otable_mutex: prevent curcurrent start/stop */
2256 mutex_lock(&dev->od_otable_mutex);
2257 rc = do_osd_scrub_start(dev, flags);
2258 mutex_unlock(&dev->od_otable_mutex);
2260 RETURN(rc == -EALREADY ? 0 : rc);
2263 static void do_osd_scrub_stop(struct osd_scrub *scrub)
2265 struct ptlrpc_thread *thread = &scrub->os_thread;
2266 struct l_wait_info lwi = { 0 };
2268 /* os_lock: sync status between stop and scrub thread */
2269 spin_lock(&scrub->os_lock);
2270 if (!thread_is_init(thread) && !thread_is_stopped(thread)) {
2271 thread_set_flags(thread, SVC_STOPPING);
2272 spin_unlock(&scrub->os_lock);
2273 wake_up_all(&thread->t_ctl_waitq);
2274 l_wait_event(thread->t_ctl_waitq,
2275 thread_is_stopped(thread),
2277 /* Do not skip the last lock/unlock, which can guarantee that
2278 * the caller cannot return until the OI scrub thread exit. */
2279 spin_lock(&scrub->os_lock);
2281 spin_unlock(&scrub->os_lock);
2284 static void osd_scrub_stop(struct osd_device *dev)
2286 /* od_otable_mutex: prevent curcurrent start/stop */
2287 mutex_lock(&dev->od_otable_mutex);
2288 dev->od_scrub.os_paused = 1;
2289 do_osd_scrub_stop(&dev->od_scrub);
2290 mutex_unlock(&dev->od_otable_mutex);
2293 /* OI scrub setup/cleanup */
2295 static const char osd_scrub_name[] = "OI_scrub";
2297 int osd_scrub_setup(const struct lu_env *env, struct osd_device *dev)
2299 struct osd_thread_info *info = osd_oti_get(env);
2300 struct osd_scrub *scrub = &dev->od_scrub;
2301 struct lvfs_run_ctxt *ctxt = &scrub->os_ctxt;
2302 struct scrub_file *sf = &scrub->os_file;
2303 struct super_block *sb = osd_sb(dev);
2304 struct ldiskfs_super_block *es = LDISKFS_SB(sb)->s_es;
2305 struct lvfs_run_ctxt saved;
2307 struct inode *inode;
2308 struct lu_fid *fid = &info->oti_fid;
2313 memset(scrub, 0, sizeof(*scrub));
2314 OBD_SET_CTXT_MAGIC(ctxt);
2315 ctxt->pwdmnt = dev->od_mnt;
2316 ctxt->pwd = dev->od_mnt->mnt_root;
2317 ctxt->fs = get_ds();
2319 init_waitqueue_head(&scrub->os_thread.t_ctl_waitq);
2320 init_rwsem(&scrub->os_rwsem);
2321 spin_lock_init(&scrub->os_lock);
2322 INIT_LIST_HEAD(&scrub->os_inconsistent_items);
2324 push_ctxt(&saved, ctxt);
2325 filp = filp_open(osd_scrub_name, O_RDWR | O_CREAT, 0644);
2327 pop_ctxt(&saved, ctxt);
2328 RETURN(PTR_ERR(filp));
2331 inode = filp->f_dentry->d_inode;
2332 /* 'What the @fid is' is not imporatant, because the object
2333 * has no OI mapping, and only is visible inside the OSD.*/
2334 lu_igif_build(fid, inode->i_ino, inode->i_generation);
2335 rc = osd_ea_fid_set(info, inode, fid, LMAC_NOT_IN_OI, 0);
2337 filp_close(filp, 0);
2338 pop_ctxt(&saved, ctxt);
2342 scrub->os_inode = igrab(inode);
2343 filp_close(filp, 0);
2344 pop_ctxt(&saved, ctxt);
2346 rc = osd_scrub_file_load(scrub);
2347 if (rc == -ENOENT) {
2348 osd_scrub_file_init(scrub, es->s_uuid);
2349 /* If the "/O" dir does not exist when mount (indicated by
2350 * osd_device::od_maybe_new), neither for the "/OI_scrub",
2351 * then it is quite probably that the device is a new one,
2352 * under such case, mark it as SIF_NO_HANDLE_OLD_FID.
2354 * For the rare case that "/O" and "OI_scrub" both lost on
2355 * an old device, it can be found and cleared later.
2357 * For the system with "SIF_NO_HANDLE_OLD_FID", we do not
2358 * need to check "filter_fid_old" and to convert it to
2359 * "filter_fid" for each object, and all the IGIF should
2360 * have their FID mapping in OI files already. */
2361 if (dev->od_maybe_new)
2362 sf->sf_internal_flags = SIF_NO_HANDLE_OLD_FID;
2364 } else if (rc != 0) {
2365 GOTO(cleanup_inode, rc);
2367 if (memcmp(sf->sf_uuid, es->s_uuid, 16) != 0) {
2368 osd_scrub_file_reset(scrub, es->s_uuid,SF_INCONSISTENT);
2370 } else if (sf->sf_status == SS_SCANNING) {
2371 sf->sf_status = SS_CRASHED;
2376 if (sf->sf_pos_last_checkpoint != 0)
2377 scrub->os_pos_current = sf->sf_pos_last_checkpoint + 1;
2379 scrub->os_pos_current = LDISKFS_FIRST_INO(sb) + 1;
2382 rc = osd_scrub_file_store(scrub);
2384 GOTO(cleanup_inode, rc);
2387 /* Initialize OI files. */
2388 rc = osd_oi_init(info, dev);
2390 GOTO(cleanup_inode, rc);
2392 rc = osd_initial_OI_scrub(info, dev);
2394 GOTO(cleanup_oi, rc);
2396 if (sf->sf_flags & SF_UPGRADE ||
2397 !(sf->sf_internal_flags & SIF_NO_HANDLE_OLD_FID ||
2398 sf->sf_success_count > 0)) {
2399 dev->od_igif_inoi = 0;
2400 dev->od_check_ff = dev->od_is_ost;
2402 dev->od_igif_inoi = 1;
2403 dev->od_check_ff = 0;
2406 if (sf->sf_flags & SF_INCONSISTENT)
2407 /* The 'od_igif_inoi' will be set under the
2409 * 1) new created system, or
2410 * 2) restored from file-level backup, or
2411 * 3) the upgrading completed.
2413 * The 'od_igif_inoi' may be cleared by OI scrub
2414 * later if found that the system is upgrading. */
2415 dev->od_igif_inoi = 1;
2417 if (!dev->od_noscrub &&
2418 ((sf->sf_status == SS_PAUSED) ||
2419 (sf->sf_status == SS_CRASHED &&
2420 sf->sf_flags & (SF_RECREATED | SF_INCONSISTENT |
2421 SF_UPGRADE | SF_AUTO)) ||
2422 (sf->sf_status == SS_INIT &&
2423 sf->sf_flags & (SF_RECREATED | SF_INCONSISTENT |
2425 rc = osd_scrub_start(dev, SS_AUTO_FULL);
2428 GOTO(cleanup_oi, rc);
2430 /* it is possible that dcache entries may keep objects after they are
2431 * deleted by OSD. While it looks safe this can cause object data to
2432 * stay until umount causing failures in tests calculating free space,
2433 * e.g. replay-ost-single. Since those dcache entries are not used
2434 * anymore let's just free them after use here */
2435 shrink_dcache_sb(sb);
2439 osd_oi_fini(info, dev);
2441 iput(scrub->os_inode);
2442 scrub->os_inode = NULL;
2447 void osd_scrub_cleanup(const struct lu_env *env, struct osd_device *dev)
2449 struct osd_scrub *scrub = &dev->od_scrub;
2451 LASSERT(dev->od_otable_it == NULL);
2453 if (scrub->os_inode != NULL) {
2454 osd_scrub_stop(dev);
2455 iput(scrub->os_inode);
2456 scrub->os_inode = NULL;
2458 if (dev->od_oi_table != NULL)
2459 osd_oi_fini(osd_oti_get(env), dev);
2462 /* object table based iteration APIs */
2464 static struct dt_it *osd_otable_it_init(const struct lu_env *env,
2465 struct dt_object *dt, __u32 attr,
2466 struct lustre_capa *capa)
2468 enum dt_otable_it_flags flags = attr >> DT_OTABLE_IT_FLAGS_SHIFT;
2469 enum dt_otable_it_valid valid = attr & ~DT_OTABLE_IT_FLAGS_MASK;
2470 struct osd_device *dev = osd_dev(dt->do_lu.lo_dev);
2471 struct osd_scrub *scrub = &dev->od_scrub;
2472 struct osd_otable_it *it;
2477 /* od_otable_mutex: prevent curcurrent init/fini */
2478 mutex_lock(&dev->od_otable_mutex);
2479 if (dev->od_otable_it != NULL)
2480 GOTO(out, it = ERR_PTR(-EALREADY));
2484 GOTO(out, it = ERR_PTR(-ENOMEM));
2486 dev->od_otable_it = it;
2488 it->ooi_cache.ooc_consumer_idx = -1;
2489 if (flags & DOIF_OUTUSED)
2490 it->ooi_used_outside = 1;
2492 if (flags & DOIF_RESET)
2495 if (valid & DOIV_ERROR_HANDLE) {
2496 if (flags & DOIF_FAILOUT)
2497 start |= SS_SET_FAILOUT;
2499 start |= SS_CLEAR_FAILOUT;
2502 if (valid & DOIV_DRYRUN) {
2503 if (flags & DOIF_DRYRUN)
2504 start |= SS_SET_DRYRUN;
2506 start |= SS_CLEAR_DRYRUN;
2509 rc = do_osd_scrub_start(dev, start & ~SS_AUTO_PARTIAL);
2510 if (rc < 0 && rc != -EALREADY) {
2511 dev->od_otable_it = NULL;
2513 GOTO(out, it = ERR_PTR(rc));
2516 it->ooi_cache.ooc_pos_preload = scrub->os_pos_current;
2521 mutex_unlock(&dev->od_otable_mutex);
2522 return (struct dt_it *)it;
2525 static void osd_otable_it_fini(const struct lu_env *env, struct dt_it *di)
2527 struct osd_otable_it *it = (struct osd_otable_it *)di;
2528 struct osd_device *dev = it->ooi_dev;
2530 /* od_otable_mutex: prevent curcurrent init/fini */
2531 mutex_lock(&dev->od_otable_mutex);
2532 do_osd_scrub_stop(&dev->od_scrub);
2533 LASSERT(dev->od_otable_it == it);
2535 dev->od_otable_it = NULL;
2536 mutex_unlock(&dev->od_otable_mutex);
2540 static int osd_otable_it_get(const struct lu_env *env,
2541 struct dt_it *di, const struct dt_key *key)
2546 static void osd_otable_it_put(const struct lu_env *env, struct dt_it *di)
2551 osd_otable_it_wakeup(struct osd_scrub *scrub, struct osd_otable_it *it)
2553 spin_lock(&scrub->os_lock);
2554 if (it->ooi_cache.ooc_pos_preload < scrub->os_pos_current ||
2555 scrub->os_waiting ||
2556 !thread_is_running(&scrub->os_thread))
2557 it->ooi_waiting = 0;
2559 it->ooi_waiting = 1;
2560 spin_unlock(&scrub->os_lock);
2562 return !it->ooi_waiting;
2565 static int osd_otable_it_next(const struct lu_env *env, struct dt_it *di)
2567 struct osd_otable_it *it = (struct osd_otable_it *)di;
2568 struct osd_device *dev = it->ooi_dev;
2569 struct osd_scrub *scrub = &dev->od_scrub;
2570 struct osd_otable_cache *ooc = &it->ooi_cache;
2571 struct ptlrpc_thread *thread = &scrub->os_thread;
2572 struct l_wait_info lwi = { 0 };
2576 LASSERT(it->ooi_user_ready);
2579 if (!thread_is_running(thread) && !it->ooi_used_outside)
2582 if (ooc->ooc_cached_items > 0) {
2583 ooc->ooc_cached_items--;
2584 ooc->ooc_consumer_idx = (ooc->ooc_consumer_idx + 1) &
2585 ~OSD_OTABLE_IT_CACHE_MASK;
2589 if (it->ooi_all_cached) {
2590 l_wait_event(thread->t_ctl_waitq,
2591 !thread_is_running(thread),
2596 if (scrub->os_waiting && osd_scrub_has_window(scrub, ooc)) {
2597 spin_lock(&scrub->os_lock);
2598 scrub->os_waiting = 0;
2599 wake_up_all(&scrub->os_thread.t_ctl_waitq);
2600 spin_unlock(&scrub->os_lock);
2603 if (it->ooi_cache.ooc_pos_preload >= scrub->os_pos_current)
2604 l_wait_event(thread->t_ctl_waitq,
2605 osd_otable_it_wakeup(scrub, it),
2608 if (!thread_is_running(thread) && !it->ooi_used_outside)
2611 rc = osd_otable_it_preload(env, it);
2618 static struct dt_key *osd_otable_it_key(const struct lu_env *env,
2619 const struct dt_it *di)
2624 static int osd_otable_it_key_size(const struct lu_env *env,
2625 const struct dt_it *di)
2627 return sizeof(__u64);
2630 static int osd_otable_it_rec(const struct lu_env *env, const struct dt_it *di,
2631 struct dt_rec *rec, __u32 attr)
2633 struct osd_otable_it *it = (struct osd_otable_it *)di;
2634 struct osd_otable_cache *ooc = &it->ooi_cache;
2636 *(struct lu_fid *)rec = ooc->ooc_cache[ooc->ooc_consumer_idx].oic_fid;
2638 /* Filter out Invald FID already. */
2639 LASSERTF(fid_is_sane((struct lu_fid *)rec),
2640 "Invalid FID "DFID", p_idx = %d, c_idx = %d\n",
2641 PFID((struct lu_fid *)rec),
2642 ooc->ooc_producer_idx, ooc->ooc_consumer_idx);
2647 static __u64 osd_otable_it_store(const struct lu_env *env,
2648 const struct dt_it *di)
2650 struct osd_otable_it *it = (struct osd_otable_it *)di;
2651 struct osd_otable_cache *ooc = &it->ooi_cache;
2654 if (it->ooi_user_ready && ooc->ooc_consumer_idx != -1)
2655 hash = ooc->ooc_cache[ooc->ooc_consumer_idx].oic_lid.oii_ino;
2657 hash = ooc->ooc_pos_preload;
2662 * Set the OSD layer iteration start position as the specified hash.
2664 static int osd_otable_it_load(const struct lu_env *env,
2665 const struct dt_it *di, __u64 hash)
2667 struct osd_otable_it *it = (struct osd_otable_it *)di;
2668 struct osd_device *dev = it->ooi_dev;
2669 struct osd_otable_cache *ooc = &it->ooi_cache;
2670 struct osd_scrub *scrub = &dev->od_scrub;
2674 /* Forbid to set iteration position after iteration started. */
2675 if (it->ooi_user_ready)
2678 if (hash > OSD_OTABLE_MAX_HASH)
2679 hash = OSD_OTABLE_MAX_HASH;
2681 ooc->ooc_pos_preload = hash;
2682 if (ooc->ooc_pos_preload <= LDISKFS_FIRST_INO(osd_sb(dev)))
2683 ooc->ooc_pos_preload = LDISKFS_FIRST_INO(osd_sb(dev)) + 1;
2685 it->ooi_user_ready = 1;
2686 if (!scrub->os_full_speed)
2687 wake_up_all(&scrub->os_thread.t_ctl_waitq);
2689 /* Unplug OSD layer iteration by the first next() call. */
2690 rc = osd_otable_it_next(env, (struct dt_it *)it);
2695 static int osd_otable_it_key_rec(const struct lu_env *env,
2696 const struct dt_it *di, void *key_rec)
2701 const struct dt_index_operations osd_otable_ops = {
2703 .init = osd_otable_it_init,
2704 .fini = osd_otable_it_fini,
2705 .get = osd_otable_it_get,
2706 .put = osd_otable_it_put,
2707 .next = osd_otable_it_next,
2708 .key = osd_otable_it_key,
2709 .key_size = osd_otable_it_key_size,
2710 .rec = osd_otable_it_rec,
2711 .store = osd_otable_it_store,
2712 .load = osd_otable_it_load,
2713 .key_rec = osd_otable_it_key_rec,
2717 /* high priority inconsistent items list APIs */
2719 #define SCRUB_BAD_OIMAP_DECAY_INTERVAL 60
2721 int osd_oii_insert(struct osd_device *dev, struct osd_idmap_cache *oic,
2724 struct osd_inconsistent_item *oii;
2725 struct osd_scrub *scrub = &dev->od_scrub;
2726 struct ptlrpc_thread *thread = &scrub->os_thread;
2731 if (unlikely(oii == NULL))
2734 INIT_LIST_HEAD(&oii->oii_list);
2735 oii->oii_cache = *oic;
2736 oii->oii_insert = insert;
2738 if (scrub->os_partial_scan) {
2739 __u64 now = cfs_time_current_sec();
2741 /* If there haven't been errors in a long time,
2742 * decay old count until either the errors are
2743 * gone or we reach the current interval. */
2744 while (unlikely(scrub->os_bad_oimap_count > 0 &&
2745 scrub->os_bad_oimap_time +
2746 SCRUB_BAD_OIMAP_DECAY_INTERVAL < now)) {
2747 scrub->os_bad_oimap_count >>= 1;
2748 scrub->os_bad_oimap_time +=
2749 SCRUB_BAD_OIMAP_DECAY_INTERVAL;
2752 scrub->os_bad_oimap_time = now;
2753 if (++scrub->os_bad_oimap_count > dev->od_full_scrub_speed)
2754 scrub->os_full_scrub = 1;
2757 spin_lock(&scrub->os_lock);
2758 if (unlikely(!thread_is_running(thread))) {
2759 spin_unlock(&scrub->os_lock);
2764 if (list_empty(&scrub->os_inconsistent_items))
2766 list_add_tail(&oii->oii_list, &scrub->os_inconsistent_items);
2767 spin_unlock(&scrub->os_lock);
2770 wake_up_all(&thread->t_ctl_waitq);
2775 int osd_oii_lookup(struct osd_device *dev, const struct lu_fid *fid,
2776 struct osd_inode_id *id)
2778 struct osd_scrub *scrub = &dev->od_scrub;
2779 struct osd_inconsistent_item *oii;
2782 spin_lock(&scrub->os_lock);
2783 list_for_each_entry(oii, &scrub->os_inconsistent_items, oii_list) {
2784 if (lu_fid_eq(fid, &oii->oii_cache.oic_fid)) {
2785 *id = oii->oii_cache.oic_lid;
2786 spin_unlock(&scrub->os_lock);
2790 spin_unlock(&scrub->os_lock);
2797 static const char *scrub_status_names[] = {
2808 static const char *scrub_flags_names[] = {
2816 static const char *scrub_param_names[] = {
2822 static int scrub_bits_dump(struct seq_file *m, int bits, const char *names[],
2829 rc = seq_printf(m, "%s:%c", prefix, bits != 0 ? ' ' : '\n');
2833 for (i = 0, flag = 1; bits != 0; i++, flag = 1 << i) {
2836 rc = seq_printf(m, "%s%c", names[i],
2837 bits != 0 ? ',' : '\n');
2845 static int scrub_time_dump(struct seq_file *m, __u64 time, const char *prefix)
2850 rc = seq_printf(m, "%s: "LPU64" seconds\n", prefix,
2851 cfs_time_current_sec() - time);
2853 rc = seq_printf(m, "%s: N/A\n", prefix);
2857 static int scrub_pos_dump(struct seq_file *m, __u64 pos, const char *prefix)
2862 rc = seq_printf(m, "%s: "LPU64"\n", prefix, pos);
2864 rc = seq_printf(m, "%s: N/A\n", prefix);
2868 int osd_scrub_dump(struct seq_file *m, struct osd_device *dev)
2870 struct osd_scrub *scrub = &dev->od_scrub;
2871 struct scrub_file *sf = &scrub->os_file;
2876 down_read(&scrub->os_rwsem);
2877 rc = seq_printf(m, "name: OI_scrub\n"
2881 sf->sf_magic, (int)sf->sf_oi_count,
2882 scrub_status_names[sf->sf_status]);
2886 rc = scrub_bits_dump(m, sf->sf_flags, scrub_flags_names,
2891 rc = scrub_bits_dump(m, sf->sf_param, scrub_param_names,
2896 rc = scrub_time_dump(m, sf->sf_time_last_complete,
2897 "time_since_last_completed");
2901 rc = scrub_time_dump(m, sf->sf_time_latest_start,
2902 "time_since_latest_start");
2906 rc = scrub_time_dump(m, sf->sf_time_last_checkpoint,
2907 "time_since_last_checkpoint");
2911 rc = scrub_pos_dump(m, sf->sf_pos_latest_start,
2912 "latest_start_position");
2916 rc = scrub_pos_dump(m, sf->sf_pos_last_checkpoint,
2917 "last_checkpoint_position");
2921 rc = scrub_pos_dump(m, sf->sf_pos_first_inconsistent,
2922 "first_failure_position");
2926 checked = sf->sf_items_checked + scrub->os_new_checked;
2927 rc = seq_printf(m, "checked: "LPU64"\n"
2928 "updated: "LPU64"\n"
2930 "prior_updated: "LPU64"\n"
2931 "noscrub: "LPU64"\n"
2933 "success_count: %u\n",
2934 checked, sf->sf_items_updated, sf->sf_items_failed,
2935 sf->sf_items_updated_prior, sf->sf_items_noscrub,
2936 sf->sf_items_igif, sf->sf_success_count);
2941 if (thread_is_running(&scrub->os_thread)) {
2942 cfs_duration_t duration = cfs_time_current() -
2943 scrub->os_time_last_checkpoint;
2944 __u64 new_checked = msecs_to_jiffies(scrub->os_new_checked *
2946 __u32 rtime = sf->sf_run_time +
2947 cfs_duration_sec(duration + HALF_SEC);
2950 do_div(new_checked, duration);
2952 do_div(speed, rtime);
2953 rc = seq_printf(m, "run_time: %u seconds\n"
2954 "average_speed: "LPU64" objects/sec\n"
2955 "real-time_speed: "LPU64" objects/sec\n"
2956 "current_position: %u\n"
2957 "lf_scanned: "LPU64"\n"
2958 "lf_reparied: "LPU64"\n"
2959 "lf_failed: "LPU64"\n",
2960 rtime, speed, new_checked, scrub->os_pos_current,
2961 scrub->os_lf_scanned, scrub->os_lf_repaired,
2962 scrub->os_lf_failed);
2964 if (sf->sf_run_time != 0)
2965 do_div(speed, sf->sf_run_time);
2966 rc = seq_printf(m, "run_time: %u seconds\n"
2967 "average_speed: "LPU64" objects/sec\n"
2968 "real-time_speed: N/A\n"
2969 "current_position: N/A\n"
2970 "lf_scanned: "LPU64"\n"
2971 "lf_reparied: "LPU64"\n"
2972 "lf_failed: "LPU64"\n",
2973 sf->sf_run_time, speed, scrub->os_lf_scanned,
2974 scrub->os_lf_repaired, scrub->os_lf_failed);
2978 up_read(&scrub->os_rwsem);
2979 return (rc < 0 ? -ENOSPC : 0);