1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * lustre/fid/fid_store.c
5 * Lustre Sequence Manager
7 * Copyright (c) 2006 Cluster File Systems, Inc.
8 * Author: Yury Umanets <umka@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
32 #define DEBUG_SUBSYSTEM S_FID
35 # include <libcfs/libcfs.h>
36 # include <linux/module.h>
37 #else /* __KERNEL__ */
38 # include <liblustre.h>
42 #include <obd_class.h>
43 #include <dt_object.h>
44 #include <md_object.h>
45 #include <obd_support.h>
46 #include <lustre_req_layout.h>
47 #include <lustre_fid.h>
48 #include "fid_internal.h"
51 struct seq_store_capsule {
52 struct lu_range ssc_space;
53 struct lu_range ssc_super;
57 SEQ_TXN_STORE_CREDITS = 20
60 /* this function implies that caller takes care about locking */
62 seq_store_write(struct lu_server_seq *seq,
63 const struct lu_context *ctx)
65 struct dt_object *dt_obj = seq->seq_obj;
66 struct dt_device *dt_dev = seq->seq_dev;
67 struct seq_store_capsule capsule;
74 /* stub here, will fix it later */
75 txn.tp_credits = SEQ_TXN_STORE_CREDITS;
77 th = dt_dev->dd_ops->dt_trans_start(ctx, dt_dev, &txn);
79 rc = dt_obj->do_body_ops->dbo_write(ctx, dt_obj,
83 if (rc == sizeof(capsule)) {
89 dt_dev->dd_ops->dt_trans_stop(ctx, th);
97 /* this function implies that caller takes care about locking or locking is not
98 * needed (init time). */
100 seq_store_read(struct lu_server_seq *seq,
101 const struct lu_context *ctx)
103 struct dt_object *dt_obj = seq->seq_obj;
104 struct seq_store_capsule capsule;
109 rc = dt_obj->do_body_ops->dbo_read(ctx, dt_obj,
111 sizeof(capsule), &pos);
112 if (rc == sizeof(capsule)) {
113 seq->seq_space = capsule.ssc_space;
114 seq->seq_super = capsule.ssc_super;
116 } else if (rc == 0) {
118 } else if (rc >= 0) {
119 CERROR("read only %d bytes of %d\n",
120 rc, sizeof(capsule));
128 seq_store_init(struct lu_server_seq *seq,
129 const struct lu_context *ctx)
131 struct dt_device *dt = seq->seq_dev;
132 struct dt_object *dt_obj;
136 LASSERT(seq->seq_service == NULL);
138 dt_obj = dt_store_open(ctx, dt, "seq", &seq->seq_fid);
139 if (!IS_ERR(dt_obj)) {
140 seq->seq_obj = dt_obj;
143 CERROR("cannot find \"seq\" obj %d\n",
144 (int)PTR_ERR(dt_obj));
145 rc = PTR_ERR(dt_obj);
152 seq_store_fini(struct lu_server_seq *seq,
153 const struct lu_context *ctx)
156 if (seq->seq_obj != NULL) {
157 lu_object_put(ctx, &seq->seq_obj->do_lu);