+/**
+ * Remove the name entry from the .lustre/lost+found directory.
+ *
+ * No need to care about the object referenced by the name entry,
+ * either the name entry is invalid or redundant, or the referenced
+ * object has been processed or will be handled by others.
+ *
+ * \param[in] env pointer to the thread context
+ * \param[in] lfsck pointer to the lfsck instance
+ * \param[in] name the name for the name entry to be removed
+ *
+ * \retval 0 for success
+ * \retval negative error number on failure
+ */
+static int lfsck_lpf_remove_name_entry(const struct lu_env *env,
+ struct lfsck_instance *lfsck,
+ const char *name)
+{
+ struct dt_object *parent = lfsck->li_lpf_root_obj;
+ struct dt_device *dev = lfsck->li_next;
+ struct thandle *th;
+ struct lustre_handle lh = { 0 };
+ int rc;
+ ENTRY;
+
+ rc = lfsck_ibits_lock(env, lfsck, parent, &lh,
+ MDS_INODELOCK_UPDATE, LCK_EX);
+ if (rc != 0)
+ RETURN(rc);
+
+ th = dt_trans_create(env, dev);
+ if (IS_ERR(th))
+ GOTO(unlock, rc = PTR_ERR(th));
+
+ rc = dt_declare_delete(env, parent, (const struct dt_key *)name, th);
+ if (rc != 0)
+ GOTO(stop, rc);
+
+ rc = dt_declare_ref_del(env, parent, th);
+ if (rc != 0)
+ GOTO(stop, rc);
+
+ rc = dt_trans_start(env, dev, th);
+ if (rc != 0)
+ GOTO(stop, rc);
+
+ rc = dt_delete(env, parent, (const struct dt_key *)name, th,
+ BYPASS_CAPA);
+ if (rc != 0)
+ GOTO(stop, rc);
+
+ dt_write_lock(env, parent, 0);
+ rc = dt_ref_del(env, parent, th);
+ dt_write_unlock(env, parent);
+
+ GOTO(stop, rc);
+
+stop:
+ dt_trans_stop(env, dev, th);
+
+unlock:
+ lfsck_ibits_unlock(&lh, LCK_EX);
+
+ CDEBUG(D_LFSCK, "%s: remove name entry "DFID"/%s: rc = %d\n",
+ lfsck_lfsck2name(lfsck), PFID(lfsck_dto2fid(parent)), name, rc);
+
+ return rc;
+}
+