-int osd_compat_objid_insert(struct osd_thread_info *info,
- struct osd_device *osd,
- const struct lu_fid *fid,
- const struct osd_inode_id *id,
- struct thandle *th)
-{
- struct osd_compat_objid *map;
- struct dentry *d;
- struct ost_id *ostid = &info->oti_ostid;
- int dirn, rc = 0;
- char name[32];
- ENTRY;
-
- map = osd->od_ost_map;
- LASSERT(map);
- LASSERT(map->root);
- LASSERT(map->subdir_count > 0);
- LASSERT(map->groups[ostid->oi_seq].groot);
-
- /* map fid to group:objid */
- fid_ostid_pack(fid, ostid);
- dirn = ostid->oi_id & (map->subdir_count - 1);
- d = map->groups[ostid->oi_seq].dirs[dirn];
- LASSERT(d);
-
- sprintf(name, "%llu", ostid->oi_id);
- rc = osd_compat_add_entry(info, osd, d, name, id, th);
-
- RETURN(rc);
-}
-
-int osd_compat_objid_delete(struct osd_thread_info *info,
- struct osd_device *osd,
- const struct lu_fid *fid, struct thandle *th)
-{
- struct osd_compat_objid *map;
- struct dentry *d;
- struct ost_id *ostid = &info->oti_ostid;
- int dirn, rc = 0;
- char name[32];
- ENTRY;
-
- map = osd->od_ost_map;
- LASSERT(map);
- LASSERT(map->root);
- LASSERT(map->subdir_count > 0);
- LASSERT(map->groups[ostid->oi_seq].groot);
-
- /* map fid to group:objid */
- fid_ostid_pack(fid, ostid);
- dirn = ostid->oi_id & (map->subdir_count - 1);
- d = map->groups[ostid->oi_seq].dirs[dirn];
- LASSERT(d);
-
- sprintf(name, "%llu", ostid->oi_id);
- rc = osd_compat_del_entry(info, osd, d, name, th);
-
- RETURN(rc);
-}
-
-struct named_oid {
- unsigned long oid;
- char *name;
-};
-
-static const struct named_oid oids[] = {
- { FLD_INDEX_OID, "fld" },
- { FID_SEQ_CTL_OID, "seq_ctl" },
- { FID_SEQ_SRV_OID, "seq_srv" },
- { MDD_ROOT_INDEX_OID, "" /* "ROOT" */ },
- { MDD_ORPHAN_OID, "" /* "PENDING" */ },
- { MDD_LOV_OBJ_OID, LOV_OBJID },
- { MDD_CAPA_KEYS_OID, "" /* CAPA_KEYS */ },
- { MDT_LAST_RECV_OID, LAST_RCVD },
- { LFSCK_BOOKMARK_OID, "" /* "lfsck_bookmark" */ },
- { OTABLE_IT_OID, "" /* "otable iterator" */},
- { OFD_LAST_RECV_OID, LAST_RCVD },
- { OFD_LAST_GROUP_OID, "LAST_GROUP" },
- { LLOG_CATALOGS_OID, "CATALOGS" },
- { MGS_CONFIGS_OID, "" /* MOUNT_CONFIGS_DIR */ },
- { OFD_HEALTH_CHECK_OID, HEALTH_CHECK },
- { 0, NULL }
-};
-
-static char *oid2name(const unsigned long oid)
-{
- int i = 0;
-
- while (oids[i].oid) {
- if (oids[i].oid == oid)
- return oids[i].name;
- i++;
- }
- return NULL;
-}
-
-int osd_compat_spec_insert(struct osd_thread_info *info,
- struct osd_device *osd, const struct lu_fid *fid,
- const struct osd_inode_id *id, struct thandle *th)
-{
- struct osd_compat_objid *map = osd->od_ost_map;
- struct dentry *root = osd_sb(osd)->s_root;
- char *name;
- int rc = 0;
- int seq;
- ENTRY;
-
- if (fid_oid(fid) >= OFD_GROUP0_LAST_OID &&
- fid_oid(fid) < OFD_GROUP4K_LAST_OID) {
- /* on creation of LAST_ID we create O/<group> hierarchy */
- LASSERT(map);
- seq = fid_oid(fid) - OFD_GROUP0_LAST_OID;
- LASSERT(seq < MAX_OBJID_GROUP);
- LASSERT(map->groups[seq].groot);
- rc = osd_compat_add_entry(info, osd, map->groups[seq].groot,
- "LAST_ID", id, th);
- } else {
- name = oid2name(fid_oid(fid));
- if (name == NULL)
- CWARN("UNKNOWN COMPAT FID "DFID"\n", PFID(fid));
- else if (name[0])
- rc = osd_compat_add_entry(info, osd, root, name, id,
- th);
- }
-
- RETURN(rc);
-}
-
-int osd_compat_spec_lookup(struct osd_thread_info *info,
- struct osd_device *osd, const struct lu_fid *fid,
- struct osd_inode_id *id)
-{
- struct dentry *root;
+int osd_obj_map_insert(struct osd_thread_info *info,
+ struct osd_device *osd,
+ const struct lu_fid *fid,
+ const struct osd_inode_id *id,
+ handle_t *th)
+{
+ struct osd_obj_map *map;
+ struct osd_obj_seq *osd_seq;
+ struct dentry *d;
+ struct ost_id *ostid = &info->oti_ostid;
+ u64 oid;
+ int dirn, rc = 0;
+ char name[32];
+
+ ENTRY;
+
+ map = osd->od_ost_map;
+ LASSERT(map);
+
+ /* map fid to seq:objid */
+ fid_to_ostid(fid, ostid);
+
+ oid = ostid_id(ostid);
+ osd_seq = osd_seq_load(info, osd, ostid_seq(ostid));
+ if (IS_ERR(osd_seq))
+ RETURN(PTR_ERR(osd_seq));
+
+ dirn = oid & (osd_seq->oos_subdir_count - 1);
+ d = osd_seq->oos_dirs[dirn];
+ LASSERT(d);
+
+ osd_oid_name(name, sizeof(name), fid, oid);
+
+again:
+ rc = osd_obj_add_entry(info, osd, d, name, id, th);
+ if (rc == -EEXIST) {
+ rc = osd_obj_update_entry(info, osd, d, name, fid, id, th);
+ if (unlikely(rc == -ENOENT))
+ goto again;
+
+ if (unlikely(rc == 1))
+ RETURN(0);
+ }
+
+ RETURN(rc);
+}
+
+int osd_obj_map_delete(struct osd_thread_info *info, struct osd_device *osd,
+ const struct lu_fid *fid, handle_t *th)
+{
+ struct osd_obj_map *map;
+ struct osd_obj_seq *osd_seq;
+ struct dentry *d;
+ struct ost_id *ostid = &info->oti_ostid;
+ int dirn, rc = 0;
+ char name[32];
+
+ ENTRY;
+
+ map = osd->od_ost_map;
+ LASSERT(map);
+
+ /* map fid to seq:objid */
+ fid_to_ostid(fid, ostid);
+
+ osd_seq = osd_seq_load(info, osd, ostid_seq(ostid));
+ if (IS_ERR(osd_seq))
+ GOTO(cleanup, rc = PTR_ERR(osd_seq));
+
+ dirn = ostid_id(ostid) & (osd_seq->oos_subdir_count - 1);
+ d = osd_seq->oos_dirs[dirn];
+ LASSERT(d);
+
+ osd_oid_name(name, sizeof(name), fid, ostid_id(ostid));
+ rc = osd_obj_del_entry(info, osd, d, name, th);
+cleanup:
+ RETURN(rc);
+}
+
+int osd_obj_map_update(struct osd_thread_info *info,
+ struct osd_device *osd,
+ const struct lu_fid *fid,
+ const struct osd_inode_id *id,
+ handle_t *th)
+{
+ struct osd_obj_seq *osd_seq;
+ struct dentry *d;
+ struct ost_id *ostid = &info->oti_ostid;
+ int dirn, rc = 0;
+ char name[32];
+
+ ENTRY;
+
+ fid_to_ostid(fid, ostid);
+ osd_seq = osd_seq_load(info, osd, ostid_seq(ostid));
+ if (IS_ERR(osd_seq))
+ RETURN(PTR_ERR(osd_seq));
+
+ dirn = ostid_id(ostid) & (osd_seq->oos_subdir_count - 1);
+ d = osd_seq->oos_dirs[dirn];
+ LASSERT(d);
+
+ osd_oid_name(name, sizeof(name), fid, ostid_id(ostid));
+ rc = osd_obj_update_entry(info, osd, d, name, fid, id, th);
+
+ RETURN(rc);
+}
+
+int osd_obj_map_recover(struct osd_thread_info *info,
+ struct osd_device *osd,
+ struct inode *src_parent,
+ struct dentry *src_child,
+ const struct lu_fid *fid)
+{
+ struct osd_obj_seq *osd_seq;
+ struct dentry *tgt_parent;
+ struct dentry *tgt_child = &info->oti_child_dentry;
+ struct inode *dir;
+ struct inode *inode = src_child->d_inode;
+ struct ost_id *ostid = &info->oti_ostid;
+ handle_t *jh;
+ struct ldiskfs_dir_entry_2 *de;
+ struct buffer_head *bh;
+ char name[32];
+ int dirn;
+ int rc = 0;
+
+ ENTRY;
+
+ if (fid_is_last_id(fid)) {
+ osd_seq = osd_seq_load(info, osd, fid_seq(fid));
+ if (IS_ERR(osd_seq))
+ RETURN(PTR_ERR(osd_seq));
+
+ tgt_parent = osd_seq->oos_root;
+ tgt_child->d_name.name = "LAST_ID";
+ tgt_child->d_name.len = strlen("LAST_ID");
+ } else {
+ fid_to_ostid(fid, ostid);
+ osd_seq = osd_seq_load(info, osd, ostid_seq(ostid));
+ if (IS_ERR(osd_seq))
+ RETURN(PTR_ERR(osd_seq));
+
+ dirn = ostid_id(ostid) & (osd_seq->oos_subdir_count - 1);
+ tgt_parent = osd_seq->oos_dirs[dirn];
+ osd_oid_name(name, sizeof(name), fid, ostid_id(ostid));
+ tgt_child->d_name.name = name;
+ tgt_child->d_name.len = strlen(name);
+ }
+ LASSERT(tgt_parent != NULL);
+
+ dir = tgt_parent->d_inode;
+ tgt_child->d_name.hash = 0;
+ tgt_child->d_parent = tgt_parent;
+ tgt_child->d_inode = inode;
+
+ /* The non-initialized src_child may be destroyed. */
+ jh = osd_journal_start_sb(osd_sb(osd), LDISKFS_HT_MISC,
+ osd_dto_credits_noquota[DTO_INDEX_DELETE] +
+ osd_dto_credits_noquota[DTO_INDEX_INSERT] +
+ osd_dto_credits_noquota[DTO_OBJECT_DELETE]);
+ if (IS_ERR(jh))
+ RETURN(PTR_ERR(jh));
+
+ ll_vfs_dq_init(src_parent);
+ ll_vfs_dq_init(dir);
+
+ inode_lock(src_parent);
+ inode_lock(dir);
+ bh = osd_ldiskfs_find_entry(dir, &tgt_child->d_name, &de, NULL, NULL);
+ if (!IS_ERR(bh)) {
+ /*
+ * XXX: If some other object occupied the same slot. And If such
+ * inode is zero-sized and with SUID+SGID, then means it is
+ * a new created one. Maybe we can remove it and insert the
+ * original one back to the /O/<seq>/d<x>. But there are
+ * something to be considered:
+ *
+ * 1) The OST-object under /lost+found has crashed LMA.
+ * So it should not conflict with the current one.
+ *
+ * 2) There are race conditions that: someone may just want
+ * to modify the current one. Even if the OI scrub takes
+ * the object lock when remove the current one, it still
+ * cause the modification to be lost becasue the target
+ * has been removed when the RPC service thread waiting
+ * for the lock.
+ *
+ * So keep it there before we have suitable solution.
+ */
+ brelse(bh);
+ inode_unlock(dir);
+ inode_unlock(src_parent);
+ ldiskfs_journal_stop(jh);
+
+ rc = -EEXIST;
+ /* If the src object has never been modified, then remove it. */
+ if (inode->i_size == 0 && inode->i_mode & S_ISUID &&
+ inode->i_mode & S_ISGID) {
+ rc = ll_vfs_unlink(src_parent, src_child);
+ if (unlikely(rc == -ENOENT))
+ rc = 0;
+ }
+ if (rc)
+ RETURN(rc);
+ }
+
+ bh = osd_ldiskfs_find_entry(src_parent, &src_child->d_name, &de,
+ NULL, NULL);
+ if (unlikely(IS_ERR(bh)))
+ GOTO(unlock, rc = PTR_ERR(bh));
+
+ rc = ldiskfs_delete_entry(jh, src_parent, de, bh);
+ brelse(bh);
+ if (rc != 0)
+ GOTO(unlock, rc);
+
+ rc = osd_ldiskfs_add_entry(info, osd, jh, tgt_child, inode, NULL);
+
+ GOTO(unlock, rc);
+
+unlock:
+ inode_unlock(dir);
+ inode_unlock(src_parent);
+ ldiskfs_journal_stop(jh);
+ return rc;
+}
+
+static struct dentry *
+osd_object_spec_find(struct osd_thread_info *info, struct osd_device *osd,
+ const struct lu_fid *fid, char **name)
+{
+ struct dentry *root = ERR_PTR(-ENOENT);
+
+ if (fid_is_last_id(fid)) {
+ struct osd_obj_seq *osd_seq;
+
+ /* on creation of LAST_ID we create O/<seq> hierarchy */
+ osd_seq = osd_seq_load(info, osd, fid_seq(fid));
+ if (IS_ERR(osd_seq))
+ RETURN((struct dentry *)osd_seq);
+
+ *name = "LAST_ID";
+ root = osd_seq->oos_root;
+ } else {
+ *name = osd_lf_fid2name(fid);
+ if (*name == NULL)
+ CWARN("UNKNOWN COMPAT FID "DFID"\n", PFID(fid));
+ else if ((*name)[0])
+ root = osd_sb(osd)->s_root;
+ }
+
+ return root;
+}
+
+int osd_obj_spec_update(struct osd_thread_info *info, struct osd_device *osd,
+ const struct lu_fid *fid, const struct osd_inode_id *id,
+ handle_t *th)
+{
+ struct dentry *root;
+ char *name = NULL;
+ int rc;
+
+ ENTRY;
+
+ root = osd_object_spec_find(info, osd, fid, &name);
+ if (!IS_ERR(root)) {
+ rc = osd_obj_update_entry(info, osd, root, name, fid, id, th);
+ } else {
+ rc = PTR_ERR(root);
+ if (rc == -ENOENT)
+ rc = 1;
+ }
+
+ RETURN(rc);
+}
+
+int osd_obj_spec_insert(struct osd_thread_info *info, struct osd_device *osd,
+ const struct lu_fid *fid, const struct osd_inode_id *id,
+ handle_t *th)
+{
+ struct dentry *root;
+ char *name = NULL;
+ int rc;
+
+ ENTRY;
+
+ root = osd_object_spec_find(info, osd, fid, &name);
+ if (!IS_ERR(root)) {
+ rc = osd_obj_add_entry(info, osd, root, name, id, th);
+ } else {
+ rc = PTR_ERR(root);
+ if (rc == -ENOENT)
+ rc = 0;
+ }
+
+ RETURN(rc);
+}
+
+int osd_obj_spec_lookup(struct osd_thread_info *info, struct osd_device *osd,
+ const struct lu_fid *fid, struct osd_inode_id *id)
+{
+ struct dentry *root;