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"
52 SEQ_TXN_STORE_CREDITS = 20
55 /* this function implies that caller takes care about locking */
56 int seq_store_write(struct lu_server_seq *seq,
57 const struct lu_context *ctx)
59 struct dt_object *dt_obj = seq->lss_obj;
60 struct seq_thread_info *info;
61 struct dt_device *dt_dev;
67 dt_dev = lu2dt_dev(seq->lss_obj->do_lu.lo_dev);
68 info = lu_context_key_get(ctx, &seq_thread_key);
69 LASSERT(info != NULL);
71 /* stub here, will fix it later */
72 info->sti_txn.tp_credits = SEQ_TXN_STORE_CREDITS;
74 th = dt_dev->dd_ops->dt_trans_start(ctx, dt_dev, &info->sti_txn);
76 /* store ranges in le format */
77 range_to_le(&info->sti_record.ssr_space, &seq->lss_space);
78 range_to_le(&info->sti_record.ssr_super, &seq->lss_super);
80 rc = dt_obj->do_body_ops->dbo_write(ctx, dt_obj,
81 (char *)&info->sti_record,
82 sizeof(info->sti_record),
84 if (rc == sizeof(info->sti_record)) {
90 dt_dev->dd_ops->dt_trans_stop(ctx, th);
98 /* this function implies that caller takes care about locking or locking is not
99 * needed (init time). */
100 int seq_store_read(struct lu_server_seq *seq,
101 const struct lu_context *ctx)
103 struct dt_object *dt_obj = seq->lss_obj;
104 struct seq_thread_info *info;
109 info = lu_context_key_get(ctx, &seq_thread_key);
110 LASSERT(info != NULL);
112 rc = dt_obj->do_body_ops->dbo_read(ctx, dt_obj,
113 (char *)&info->sti_record,
114 sizeof(info->sti_record), &pos);
115 if (rc == sizeof(info->sti_record)) {
116 seq->lss_space = info->sti_record.ssr_space;
117 lustre_swab_lu_range(&seq->lss_space);
119 seq->lss_super = info->sti_record.ssr_super;
120 lustre_swab_lu_range(&seq->lss_super);
122 } else if (rc == 0) {
124 } else if (rc >= 0) {
125 CERROR("read only %d bytes of %d\n",
126 rc, sizeof(info->sti_record));
133 int seq_store_init(struct lu_server_seq *seq,
134 const struct lu_context *ctx,
135 struct dt_device *dt)
137 struct dt_object *dt_obj;
142 LASSERT(seq->lss_md_service == NULL);
143 LASSERT(seq->lss_dt_service == NULL);
145 dt_obj = dt_store_open(ctx, dt, "seq", &fid);
146 if (!IS_ERR(dt_obj)) {
147 seq->lss_obj = dt_obj;
150 CERROR("cannot find \"seq\" obj %d\n",
151 (int)PTR_ERR(dt_obj));
152 rc = PTR_ERR(dt_obj);
158 void seq_store_fini(struct lu_server_seq *seq,
159 const struct lu_context *ctx)
163 if (seq->lss_obj != NULL) {
164 if (!IS_ERR(seq->lss_obj))
165 lu_object_put(ctx, &seq->lss_obj->do_lu);