static const char dotdot[] = "..";
enum {
- ORPH_OP_UNLINK,
- ORPH_OP_TRUNCATE
+ ORPH_OP_UNLINK,
};
-#define ORPHAN_FILE_NAME_FORMAT "%016llx:%08x:%08x:%2x"
-#define ORPHAN_FILE_NAME_FORMAT_18 "%llx:%08x"
+/* obsolete after 2.11, needed for upgrades from older 2.x versions */
+#define ORPHAN_FILE_NAME_FORMAT_20 "%016llx:%08x:%08x:%2x"
-static struct dt_key* orph_key_fill(const struct lu_env *env,
- const struct lu_fid *lf, __u32 op)
+static struct dt_key *orph_key_fill(const struct lu_env *env,
+ const struct lu_fid *lf)
{
char *key = mdd_env_info(env)->mti_key;
- int rc;
-
- LASSERT(key);
- rc = snprintf(key, NAME_MAX + 1, ORPHAN_FILE_NAME_FORMAT,
- (long long unsigned int)fid_seq(lf),
- fid_oid(lf), fid_ver(lf), op);
- if (rc > 0)
- return (struct dt_key*) key;
- else
- return ERR_PTR(rc);
+ int rc;
+
+ LASSERT(key);
+ rc = snprintf(key, NAME_MAX + 1, DFID_NOBRACE, PFID(lf));
+ if (rc > 0)
+ return (struct dt_key *)key;
+
+ return ERR_PTR(rc);
}
-static struct dt_key* orph_key_fill_18(const struct lu_env *env,
- const struct lu_fid *lf)
+/* compatibility with orphan files created in versions before 2.11 */
+static struct dt_key *orph_key_fill_20(const struct lu_env *env,
+ const struct lu_fid *lf)
{
char *key = mdd_env_info(env)->mti_key;
- int rc;
-
- LASSERT(key);
- rc = snprintf(key, NAME_MAX + 1, ORPHAN_FILE_NAME_FORMAT_18,
- (unsigned long long)fid_seq(lf), fid_oid(lf));
- if (rc > 0)
- return (struct dt_key*) key;
- else
- return ERR_PTR(rc);
+ int rc;
+
+ LASSERT(key);
+ rc = snprintf(key, NAME_MAX + 1, ORPHAN_FILE_NAME_FORMAT_20,
+ fid_seq(lf), fid_oid(lf), fid_ver(lf), ORPH_OP_UNLINK);
+ if (rc > 0)
+ return (struct dt_key *)key;
+
+ return ERR_PTR(rc);
}
static inline void mdd_orphan_write_lock(const struct lu_env *env,
}
-int orph_declare_index_insert(const struct lu_env *env,
- struct mdd_object *obj,
+int orph_declare_index_insert(const struct lu_env *env, struct mdd_object *obj,
umode_t mode, struct thandle *th)
{
- struct dt_insert_rec *rec = &mdd_env_info(env)->mti_dt_rec;
- struct mdd_device *mdd = mdo2mdd(&obj->mod_obj);
- struct dt_key *key;
- int rc;
+ struct dt_insert_rec *rec = &mdd_env_info(env)->mti_dt_rec;
+ struct mdd_device *mdd = mdo2mdd(&obj->mod_obj);
+ struct dt_key *key;
+ int rc;
- key = orph_key_fill(env, mdo2fid(obj), ORPH_OP_UNLINK);
+ key = orph_key_fill(env, mdo2fid(obj));
rec->rec_fid = mdo2fid(obj);
rec->rec_type = mode;
RETURN(rc);
}
-int orph_declare_index_delete(const struct lu_env *env,
- struct mdd_object *obj,
-
- struct thandle *th)
+int orph_declare_index_delete(const struct lu_env *env, struct mdd_object *obj,
+ struct thandle *th)
{
- struct mdd_device *mdd = mdo2mdd(&obj->mod_obj);
- struct dt_key *key;
- int rc;
+ struct mdd_device *mdd = mdo2mdd(&obj->mod_obj);
+ struct dt_key *key;
+ int rc;
- key = orph_key_fill(env, mdo2fid(obj), ORPH_OP_UNLINK);
+ key = orph_key_fill(env, mdo2fid(obj));
rc = dt_declare_delete(env, mdd->mdd_orphans, key, th);
- if (rc)
- return rc;
+ if (rc)
+ return rc;
rc = mdo_declare_ref_del(env, obj, th);
if (rc)
return rc;
}
-static int orph_index_delete(const struct lu_env *env,
- struct mdd_object *obj,
- __u32 op,
- struct thandle *th)
+static int orph_index_delete(const struct lu_env *env, struct mdd_object *obj,
+ __u32 op, struct thandle *th)
{
- struct mdd_device *mdd = mdo2mdd(&obj->mod_obj);
- struct dt_object *dor = mdd->mdd_orphans;
- struct dt_key *key;
- int rc;
+ struct mdd_device *mdd = mdo2mdd(&obj->mod_obj);
+ struct dt_object *dor = mdd->mdd_orphans;
+ struct dt_key *key;
+ int rc;
- ENTRY;
+ ENTRY;
- LASSERT(mdd_write_locked(env, obj) != 0);
- LASSERT(obj->mod_flags & ORPHAN_OBJ);
- LASSERT(obj->mod_count == 0);
+ LASSERT(mdd_write_locked(env, obj) != 0);
+ LASSERT(obj->mod_flags & ORPHAN_OBJ);
+ LASSERT(obj->mod_count == 0);
- LASSERT(dor);
+ LASSERT(dor);
- key = orph_key_fill(env, mdo2fid(obj), op);
- mdd_orphan_write_lock(env, mdd);
+ key = orph_key_fill(env, mdo2fid(obj), op);
+ mdd_orphan_write_lock(env, mdd);
- rc = mdd_orphan_delete_obj(env, mdd, key, th);
+ rc = mdd_orphan_delete_obj(env, mdd, key, th);
- if (rc == -ENOENT) {
- key = orph_key_fill_18(env, mdo2fid(obj));
- rc = mdd_orphan_delete_obj(env, mdd, key, th);
- }
+ if (rc == -ENOENT) {
+ key = orph_key_fill_20(env, mdo2fid(obj));
+ rc = mdd_orphan_delete_obj(env, mdd, key, th);
+ }
- if (!rc) {
- /* lov objects will be destroyed by caller */
- mdo_ref_del(env, obj, th);
- if (S_ISDIR(mdd_object_type(obj))) {
- mdo_ref_del(env, obj, th);
- mdd_orphan_ref_del(env, mdd, th);
- }
- obj->mod_flags &= ~ORPHAN_OBJ;
- } else {
- CERROR("could not delete object: rc = %d\n",rc);
- }
+ if (!rc) {
+ /* lov objects will be destroyed by caller */
+ mdo_ref_del(env, obj, th);
+ if (S_ISDIR(mdd_object_type(obj))) {
+ mdo_ref_del(env, obj, th);
+ mdd_orphan_ref_del(env, mdd, th);
+ }
+ obj->mod_flags &= ~ORPHAN_OBJ;
+ } else {
+ CERROR("%s: could not delete orphan object "DFID": rc = %d\n",
+ mdd2obd_dev(mdd)->obd_name, PFID(mdo2fid(obj)), rc);
+ }
- mdd_orphan_write_unlock(env, mdd);
- RETURN(rc);
+ mdd_orphan_write_unlock(env, mdd);
+ RETURN(rc);
}
* \retval 0 success
* \retval -ve index operation error.
*/
-int __mdd_orphan_add(const struct lu_env *env,
- struct mdd_object *obj, struct thandle *th)
+int __mdd_orphan_add(const struct lu_env *env, struct mdd_object *obj,
+ struct thandle *th)
{
- return orph_index_insert(env, obj, ORPH_OP_UNLINK, th);
+ return orph_index_insert(env, obj, th);
}
/**
* \retval 0 success
* \retval -ve index operation error.
*/
-int __mdd_orphan_del(const struct lu_env *env,
- struct mdd_object *obj, struct thandle *th)
+int __mdd_orphan_del(const struct lu_env *env, struct mdd_object *obj,
+ struct thandle *th)
{
- return orph_index_delete(env, obj, ORPH_OP_UNLINK, th);
+ return orph_index_delete(env, obj, th);
}