1 /* -*- MODE: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
8 * Copyright (C) 2006 Cluster File Systems, Inc.
9 * Author: Mike Pershin <tappro@clusterfs.com>
11 * This file is part of the Lustre file system, http://www.lustre.org
12 * Lustre is a trademark of Cluster File Systems, Inc.
14 * You may have signed or agreed to another license before downloading
15 * this software. If so, you are bound by the terms and conditions
16 * of that agreement, and the following does not apply to you. See the
17 * LICENSE file included with this distribution for more information.
19 * If you did not agree to a different license, then this copy of Lustre
20 * is open source software; you can redistribute it and/or modify it
21 * under the terms of version 2 of the GNU General Public License as
22 * published by the Free Software Foundation.
24 * In either case, Lustre is distributed in the hope that it will be
25 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
26 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * license text for more details.
30 # define EXPORT_SYMTAB
32 #define DEBUG_SUBSYSTEM S_MDS
35 #include <obd_class.h>
36 #include <lustre_ver.h>
37 #include <obd_support.h>
39 #include "mdd_internal.h"
41 const char orph_index_name[] = "orphans";
43 static const struct dt_index_features orph_index_features = {
44 .dif_flags = DT_IND_UPDATE,
45 .dif_keysize_min = sizeof(struct orph_key),
46 .dif_keysize_max = sizeof(struct orph_key),
47 .dif_recsize_min = sizeof(loff_t),
48 .dif_recsize_max = sizeof(loff_t)
56 static struct orph_key *orph_key_fill(const struct lu_context *ctx,
57 const struct lu_fid *lf, __u32 op)
59 struct orph_key *key = &mdd_ctx_info(ctx)->mti_orph_key;
61 key->ok_fid.f_seq = cpu_to_be64(fid_seq(lf));
62 key->ok_fid.f_oid = cpu_to_be32(fid_oid(lf));
63 key->ok_fid.f_ver = cpu_to_be32(fid_ver(lf));
64 key->ok_op = cpu_to_be32(op);
68 static int orph_index_insert(const struct lu_context *ctx,
69 struct mdd_object *obj, __u32 op,
70 loff_t *offset, struct thandle *th)
72 struct mdd_device *mdd = mdo2mdd(&obj->mod_obj);
73 struct dt_object *dor = mdd->mdd_orphans;
74 struct orph_key *key = orph_key_fill(ctx, mdo2fid(obj), op);
78 rc = dor->do_index_ops->dio_insert(ctx, dor, (struct dt_rec *)offset,
79 (struct dt_key *)key, th);
83 static int orph_index_delete(const struct lu_context *ctx,
84 struct mdd_object *obj, __u32 op,
87 struct mdd_device *mdd = mdo2mdd(&obj->mod_obj);
88 struct dt_object *dor = mdd->mdd_orphans;
89 struct orph_key *key = orph_key_fill(ctx, mdo2fid(obj), op);
93 rc = dor->do_index_ops->dio_delete(ctx, dor,
94 (struct dt_key *)key, th);
99 static int orph_index_iterate(struct lu_server_orph *orph,
100 const struct lu_context *ctx,
101 seqno_t seq, mdsno_t *mds)
103 struct dt_object *dt_obj = orph->orph_obj;
104 struct dt_rec *rec = orph_rec(ctx, 0);
108 rc = dt_obj->do_index_ops->dio_lookup(ctx, dt_obj, rec,
111 *mds = be64_to_cpu(*(__u64 *)rec);
115 int orph_index_init(const struct lu_context *ctx, struct mdd_device *mdd)
122 d = dt_store_open(ctx, mdd->mdd_child, orph_index_name, &fid);
124 mdd->mdd_orphans = d;
125 rc = d->do_ops->do_index_try(ctx, d, &orph_index_features);
127 LASSERT(d->do_index_ops != NULL);
129 CERROR("\"%s\" is not an index!\n", orph_index_name);
131 CERROR("cannot find \"%s\" obj %d\n",
132 orph_index_name, (int)PTR_ERR(d));
139 void orph_index_fini(const struct lu_context *ctx, struct mdd_device *mdd)
142 if (mdd->mdd_orphans != NULL) {
143 if (!IS_ERR(mdd->mdd_orphans))
144 lu_object_put(ctx, &mdd->mdd_orphans->do_lu);
145 mdd->mdd_orphans = NULL;
150 int __mdd_orphan_add(const struct lu_context *ctx,
151 struct mdd_object *obj,
155 return orph_index_insert(ctx, obj, ORPH_OP_UNLINK, &offset, th);
158 int __mdd_orphan_del(const struct lu_context *ctx,
159 struct mdd_object *obj,
162 return orph_index_delete(ctx, obj, ORPH_OP_UNLINK, th);