1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * lustre/fid/fid_store.c
38 * Lustre Sequence Manager
40 * Author: Yury Umanets <umka@clusterfs.com>
44 # define EXPORT_SYMTAB
46 #define DEBUG_SUBSYSTEM S_FID
49 # include <libcfs/libcfs.h>
50 # include <linux/module.h>
51 #else /* __KERNEL__ */
52 # include <liblustre.h>
56 #include <obd_class.h>
57 #include <dt_object.h>
58 #include <md_object.h>
59 #include <obd_support.h>
60 #include <lustre_req_layout.h>
61 #include <lustre_fid.h>
62 #include "fid_internal.h"
66 static struct lu_buf *seq_store_buf(struct seq_thread_info *info)
71 buf->lb_buf = &info->sti_space;
72 buf->lb_len = sizeof(info->sti_space);
76 struct thandle * seq_store_trans_start(struct lu_server_seq *seq,
77 const struct lu_env *env, int credit)
79 struct seq_thread_info *info;
80 struct dt_device *dt_dev;
84 dt_dev = lu2dt_dev(seq->lss_obj->do_lu.lo_dev);
85 info = lu_context_key_get(&env->le_ctx, &seq_thread_key);
86 LASSERT(info != NULL);
88 txn_param_init(&info->sti_txn, credit);
90 th = dt_dev->dd_ops->dt_trans_start(env, dt_dev, &info->sti_txn);
94 void seq_store_trans_stop(struct lu_server_seq *seq,
95 const struct lu_env *env,
98 struct dt_device *dt_dev;
101 dt_dev = lu2dt_dev(seq->lss_obj->do_lu.lo_dev);
103 dt_dev->dd_ops->dt_trans_stop(env, th);
106 /* This function implies that caller takes care about locking. */
107 int seq_store_write(struct lu_server_seq *seq,
108 const struct lu_env *env,
111 struct dt_object *dt_obj = seq->lss_obj;
112 struct seq_thread_info *info;
113 struct dt_device *dt_dev;
118 dt_dev = lu2dt_dev(seq->lss_obj->do_lu.lo_dev);
119 info = lu_context_key_get(&env->le_ctx, &seq_thread_key);
120 LASSERT(info != NULL);
122 /* Store ranges in le format. */
123 range_cpu_to_le(&info->sti_space, &seq->lss_space);
125 rc = dt_obj->do_body_ops->dbo_write(env, dt_obj,
127 &pos, th, BYPASS_CAPA, 1);
128 if (rc == sizeof(info->sti_space)) {
129 CDEBUG(D_INFO, "%s: Space - "DRANGE"\n",
130 seq->lss_name, PRANGE(&seq->lss_space));
132 } else if (rc >= 0) {
141 * This function implies that caller takes care about locking or locking is not
142 * needed (init time).
144 int seq_store_read(struct lu_server_seq *seq,
145 const struct lu_env *env)
147 struct dt_object *dt_obj = seq->lss_obj;
148 struct seq_thread_info *info;
153 info = lu_context_key_get(&env->le_ctx, &seq_thread_key);
154 LASSERT(info != NULL);
156 rc = dt_obj->do_body_ops->dbo_read(env, dt_obj, seq_store_buf(info),
159 if (rc == sizeof(info->sti_space)) {
160 range_le_to_cpu(&seq->lss_space, &info->sti_space);
161 CDEBUG(D_INFO, "%s: Space - "DRANGE"\n",
162 seq->lss_name, PRANGE(&seq->lss_space));
164 } else if (rc == 0) {
166 } else if (rc >= 0) {
167 CERROR("%s: Read only %d bytes of %d\n", seq->lss_name,
168 rc, (int)sizeof(info->sti_space));
175 int seq_store_init(struct lu_server_seq *seq,
176 const struct lu_env *env,
177 struct dt_device *dt)
179 struct dt_object *dt_obj;
185 name = seq->lss_type == LUSTRE_SEQ_SERVER ?
186 LUSTRE_SEQ_SRV_NAME : LUSTRE_SEQ_CTL_NAME;
188 dt_obj = dt_store_open(env, dt, "", name, &fid);
189 if (!IS_ERR(dt_obj)) {
190 seq->lss_obj = dt_obj;
193 CERROR("%s: Can't find \"%s\" obj %d\n",
194 seq->lss_name, name, (int)PTR_ERR(dt_obj));
195 rc = PTR_ERR(dt_obj);
201 void seq_store_fini(struct lu_server_seq *seq,
202 const struct lu_env *env)
206 if (seq->lss_obj != NULL) {
207 if (!IS_ERR(seq->lss_obj))
208 lu_object_put(env, &seq->lss_obj->do_lu);