1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * lustre/cmm/mdc_object.c
5 * Lustre Cluster Metadata Manager (cmm)
7 * Copyright (c) 2006 Cluster File Systems, Inc.
8 * Author: Mike Pershin <tappro@clusterfs.com>
10 * This file is part of the Lustre file system, http://www.lustre.org
11 * Lustre is a trademark of Cluster File Systems, Inc.
13 * You may have signed or agreed to another license before downloading
14 * this software. If so, you are bound by the terms and conditions
15 * of that agreement, and the following does not apply to you. See the
16 * LICENSE file included with this distribution for more information.
18 * If you did not agree to a different license, then this copy of Lustre
19 * is open source software; you can redistribute it and/or modify it
20 * under the terms of version 2 of the GNU General Public License as
21 * published by the Free Software Foundation.
23 * In either case, Lustre is distributed in the hope that it will be
24 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
25 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * license text for more details.
30 # define EXPORT_SYMTAB
33 #define DEBUG_SUBSYSTEM S_MDS
34 #include <obd_support.h>
35 #include <lustre_lib.h>
36 #include <obd_class.h>
37 #include "mdc_internal.h"
39 static struct md_object_operations mdc_mo_ops;
40 static struct md_dir_operations mdc_dir_ops;
41 static struct lu_object_operations mdc_obj_ops;
44 extern struct lu_context_key mdc_thread_key;
46 struct lu_object *mdc_object_alloc(const struct lu_context *ctx,
47 const struct lu_object_header *hdr,
50 struct mdc_object *mco;
57 lo = &mco->mco_obj.mo_lu;
58 lu_object_init(lo, NULL, ld);
59 mco->mco_obj.mo_ops = &mdc_mo_ops;
60 mco->mco_obj.mo_dir_ops = &mdc_dir_ops;
61 lo->lo_ops = &mdc_obj_ops;
67 static void mdc_object_free(const struct lu_context *ctx, struct lu_object *lo)
69 struct mdc_object *mco = lu2mdc_obj(lo);
74 static int mdc_object_init(const struct lu_context *ctx, struct lu_object *lo)
81 static void mdc_object_release(const struct lu_context *ctx,
86 static int mdc_object_exists(const struct lu_context *ctx, struct lu_object *lo)
88 /* we don't know does it exists or not - but suppose that it does*/
92 static int mdc_object_print(const struct lu_context *ctx,
93 struct seq_file *f, const struct lu_object *lo)
95 return seq_printf(f, LUSTRE_MDC0_NAME"-object@%p", lo);
98 static struct lu_object_operations mdc_obj_ops = {
99 .loo_object_init = mdc_object_init,
100 .loo_object_release = mdc_object_release,
101 .loo_object_free = mdc_object_free,
102 .loo_object_print = mdc_object_print,
103 .loo_object_exists = mdc_object_exists
106 /* md_object_operations */
107 static int mdc_object_create(const struct lu_context *ctx,
108 struct md_object *mo, struct lu_attr *attr)
110 struct mdc_device *mc = md2mdc_dev(md_device_get(mo));
111 struct mdc_thread_info *mci;
115 mci = lu_context_get_key(ctx, &mdc_thread_key);
118 mci->mci_opdata.fid1 = *lu_object_fid(&mo->mo_lu);
119 mci->mci_opdata.fid2 = { 0 };
120 mci->mci_opdata.mod_time = attr->la_mtime;
121 mci->mci_opdata.name = NULL;
122 mci->mci_opdata.namelen = 0;
124 rc = md_create(mc->mc_desc.cl_exp, &mci->mci_opdata, NULL, 0,
125 attr->la_mode, attr->la_uid, attr->la_gid, 0, 0,
130 static int mdc_ref_add(const struct lu_context *ctx, struct md_object *mo)
132 struct mdc_device *mc = md2mdc_dev(md_device_get(mo));
133 struct mdc_thread_info *mci;
137 mci = lu_context_get_key(ctx, &mdc_thread_key);
140 mci->mci_opdata.fid1 = *lu_object_fid(&mo->mo_lu);
141 mci->mci_opdata.fid2 = { 0 };
142 mci->mci_opdata.mod_time = attr->la_mtime;
143 mci->mci_opdata.name = NULL;
144 mci->mci_opdata.namelen = 0;
146 rc = md_link(mc->mc_desc.cl_exp, &mci->mci_opdata, &mci->mci_req);
151 static int mdc_ref_del(const struct lu_context *ctx, struct md_object *mo)
153 struct mdc_device *mc = md2mdc_dev(md_device_get(mo));
154 struct mdc_thread_info *mci;
158 mci = lu_context_get_key(ctx, &mdc_thread_key);
161 mci->mci_opdata.fid1 = *lu_object_fid(&mo->mo_lu);
162 mci->mci_opdata.fid2 = { 0 };
163 mci->mci_opdata.mod_time = attr->la_mtime;
164 mci->mci_opdata.name = NULL;
165 mci->mci_opdata.namelen = 0;
167 rc = md_unlink(mc->mc_desc.cl_exp, &mci->mci_opdata, &mci->mci_req);
172 static struct md_object_operations mdc_mo_ops = {
173 .moo_object_create = mdc_object_create,
174 .moo_ref_add = mdc_ref_add,
175 .moo_ref_del = mdc_ref_del,
178 /* md_dir_operations */
179 static int mdc_name_insert(const struct lu_context *ctx, struct md_object *mo,
180 const char *name, const struct lu_fid *lf)
182 struct mdc_device *mc = md2mdc_dev(md_device_get(mo));
183 struct mdc_thread_info *mci;
187 mci = lu_context_get_key(ctx, &mdc_thread_key);
190 mci->mci_opdata.fid1 = *lu_object_fid(&mo->mo_lu);
191 mci->mci_opdata.fid2 = *lf;
192 mci->mci_opdata.mod_time = attr->la_mtime;
193 //TODO: distinguish the name_insert and rename_tgt()
195 rc = md_rename(mc->mc_desc.cl_exp, &mci->mci_opdata, NULL, 0,
196 name, strlen(name), &mci->mci_req);
201 static int mdc_rename_tgt(const struct lu_context *ctx,
202 struct md_object *mo_p, struct md_object *mo_s,
203 struct md_object *mo_t, const char *name)
205 struct mdc_device *mc = md2mdc_dev(md_device_get(mo));
206 struct mdc_thread_info *mci;
210 mci = lu_context_get_key(ctx, &mdc_thread_key);
213 mci->mci_opdata.fid1 = *lu_object_fid(&mo_p->mo_lu);
214 mci->mci_opdata.fid2 = *lu_object_fid(&mo_s->mo_lu);
215 mci->mci_opdata.mod_time = attr->la_mtime;
217 rc = md_rename(mc->mc_desc.cl_exp, &mci->mci_opdata, NULL, 0,
218 name, strlen(name), &mci->mci_req);
223 static struct md_dir_operations mdc_dir_ops = {
224 .mdo_name_insert = mdc_name_insert,
225 .mdo_rename_tgt = mdc_rename_tgt,
229 struct lu_object *mdc_object_alloc(const struct lu_context *ctx,
230 const struct lu_object_header *hdr,
231 struct lu_device *ld)
233 struct mdc_object *mco;
238 struct lu_object *lo;
240 lo = &mco->mco_obj.mo_lu;
241 lu_object_init(lo, NULL, ld);
242 mco->mco_obj.mo_ops = &mdc_mo_ops;
243 mco->mco_obj.mo_dir_ops = &mdc_dir_ops;
244 lo->lo_ops = &mdc_obj_ops;
250 static int mdc_object_init(const struct lu_context *ctx, struct lu_object *lo)
252 //struct mdc_device *d = lu2mdc_dev(o->lo_dev);
253 //struct lu_device *under;
254 //const struct lu_fid *fid = lu_object_fid(o);
261 static void mdc_object_free(const struct lu_context *ctx, struct lu_object *lo)
263 struct mdc_object *mco = lu2mdc_obj(lo);
268 static void mdc_object_release(const struct lu_context *ctx,
269 struct lu_object *lo)
274 static int mdc_object_exists(const struct lu_context *ctx, struct lu_object *lo)
279 static int mdc_object_print(const struct lu_context *ctx,
280 struct seq_file *f, const struct lu_object *lo)
282 return seq_printf(f, LUSTRE_MDC0_NAME"-object@%p", lo);
285 static int mdc_object_create(const struct lu_context *ctx,
286 struct md_object *mo, struct lu_attr *attr)
288 struct mdc_device *mc = md2mdc_dev(md_device_get(mo));
289 struct obd_export *exp = mc->mc_desc.cl_exp;
290 struct ptlrpc_request *req;
291 struct md_op_data op_data = {
292 .fid1 = mo->mo_lu.lo_header->loh_fid,
294 .mod_time = attr->la_mtime,
300 rc = md_create(exp, &op_data, NULL, 0, attr->la_mode, attr->la_uid,
301 attr->la_gid, 0, 0, &req);
305 static struct md_dir_operations mdc_dir_ops = {
308 static struct md_object_operations mdc_mo_ops = {
309 .moo_object_create = mdc_object_create
312 static struct lu_object_operations mdc_obj_ops = {
313 .loo_object_init = mdc_object_init,
314 .loo_object_release = mdc_object_release,
315 .loo_object_free = mdc_object_free,
316 .loo_object_print = mdc_object_print,
317 .loo_object_exists = mdc_object_exists
319 #endif /* CMM_CODE */