1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * lustre/fid/fid_request.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"
50 /* client seq mgr interface */
52 seq_client_rpc(struct lu_client_seq *seq,
53 struct lu_range *range,
56 struct obd_export *exp = seq->seq_exp;
57 int repsize = sizeof(struct lu_range);
58 int rc, reqsize = sizeof(__u32);
59 struct ptlrpc_request *req;
64 req = ptlrpc_prep_req(class_exp2cliimp(exp),
66 SEQ_QUERY, 1, &reqsize,
71 op = lustre_msg_buf(req->rq_reqmsg, 0, sizeof(*op));
74 req->rq_replen = lustre_msg_size(1, &repsize);
76 req->rq_request_portal = (opc == SEQ_ALLOC_SUPER) ?
77 SEQ_CTLR_PORTAL : SEQ_SRV_PORTAL;
79 rc = ptlrpc_queue_wait(req);
83 ran = lustre_swab_repbuf(req, 0, sizeof(*ran),
84 lustre_swab_lu_range);
87 CERROR("invalid range is returned\n");
88 GOTO(out_req, rc = -EPROTO);
92 LASSERT(range_is_sane(range));
93 LASSERT(!range_is_exhausted(range));
97 ptlrpc_req_finished(req);
102 __seq_client_alloc_opc(struct lu_client_seq *seq,
103 int opc, const char *opcname)
108 rc = seq_client_rpc(seq, &seq->seq_range, opc);
110 CDEBUG(D_INFO, "SEQ-MGR(cli): allocated "
111 "%s-sequence ["LPX64"-"LPX64"]\n",
112 opcname, seq->seq_range.lr_start,
113 seq->seq_range.lr_end);
118 /* request sequence-controller node to allocate new super-sequence. */
120 __seq_client_alloc_super(struct lu_client_seq *seq)
123 RETURN(__seq_client_alloc_opc(seq, SEQ_ALLOC_SUPER, "super"));
127 seq_client_alloc_super(struct lu_client_seq *seq)
133 rc = __seq_client_alloc_super(seq);
138 EXPORT_SYMBOL(seq_client_alloc_super);
140 /* request sequence-controller node to allocate new meta-sequence. */
142 __seq_client_alloc_meta(struct lu_client_seq *seq)
145 RETURN(__seq_client_alloc_opc(seq, SEQ_ALLOC_META, "meta"));
149 seq_client_alloc_meta(struct lu_client_seq *seq)
155 rc = __seq_client_alloc_meta(seq);
160 EXPORT_SYMBOL(seq_client_alloc_meta);
162 /* allocate new sequence for client (llite or MDC are expected to use this) */
164 __seq_client_alloc_seq(struct lu_client_seq *seq, seqno_t *seqnr)
169 LASSERT(range_is_sane(&seq->seq_range));
171 /* if we still have free sequences in meta-sequence we allocate new seq
172 * from given range, if not - allocate new meta-sequence. */
173 if (range_space(&seq->seq_range) == 0) {
174 rc = __seq_client_alloc_meta(seq);
176 CERROR("can't allocate new meta-sequence, "
182 *seqnr = seq->seq_range.lr_start;
183 seq->seq_range.lr_start += 1;
186 CDEBUG(D_INFO, "SEQ-MGR(cli): allocated "
187 "sequence ["LPX64"]\n", *seqnr);
193 seq_client_alloc_seq(struct lu_client_seq *seq, seqno_t *seqnr)
199 rc = __seq_client_alloc_seq(seq, seqnr);
204 EXPORT_SYMBOL(seq_client_alloc_seq);
207 seq_client_alloc_fid(struct lu_client_seq *seq, struct lu_fid *fid)
213 LASSERT(fid != NULL);
217 if (!fid_is_sane(&seq->seq_fid) ||
218 fid_oid(&seq->seq_fid) >= seq->seq_width)
220 /* allocate new sequence for case client hass no sequence at all
221 * or sequnece is exhausted and should be switched. */
222 rc = __seq_client_alloc_seq(seq, &seqnr);
224 CERROR("can't allocate new sequence, "
230 seq->seq_fid.f_oid = LUSTRE_FID_INIT_OID;
231 seq->seq_fid.f_seq = seqnr;
232 seq->seq_fid.f_ver = 0;
234 /* inform caller that sequnece switch is performed to allow it
235 * to setup FLD for it. */
238 seq->seq_fid.f_oid += 1;
243 LASSERT(fid_is_sane(fid));
245 CDEBUG(D_INFO, "SEQ-MGR(cli): allocated FID "DFID3"\n",
253 EXPORT_SYMBOL(seq_client_alloc_fid);
257 seq_client_proc_init(struct lu_client_seq *seq)
262 seq->seq_proc_dir = lprocfs_register(seq->seq_name,
266 if (IS_ERR(seq->seq_proc_dir)) {
267 CERROR("LProcFS failed in seq-init\n");
268 rc = PTR_ERR(seq->seq_proc_dir);
272 rc = lprocfs_add_vars(seq->seq_proc_dir,
273 seq_client_proc_list, seq);
275 CERROR("can't init sequence manager "
276 "proc, rc %d\n", rc);
283 seq->seq_proc_dir = NULL;
288 seq_client_proc_fini(struct lu_client_seq *seq)
291 if (seq->seq_proc_dir) {
292 lprocfs_remove(seq->seq_proc_dir);
293 seq->seq_proc_dir = NULL;
300 seq_client_init(struct lu_client_seq *seq,
302 struct obd_export *exp)
307 LASSERT(exp != NULL);
309 fid_zero(&seq->seq_fid);
310 range_zero(&seq->seq_range);
311 sema_init(&seq->seq_sem, 1);
312 seq->seq_exp = class_export_get(exp);
313 seq->seq_width = LUSTRE_SEQ_MAX_WIDTH;
315 snprintf(seq->seq_name, sizeof(seq->seq_name),
316 "%s-%s", LUSTRE_SEQ_NAME, uuid);
319 rc = seq_client_proc_init(seq);
323 seq_client_fini(seq);
325 CDEBUG(D_INFO|D_WARNING,
326 "Client Sequence Manager\n");
329 EXPORT_SYMBOL(seq_client_init);
331 void seq_client_fini(struct lu_client_seq *seq)
336 seq_client_proc_fini(seq);
339 if (seq->seq_exp != NULL) {
340 class_export_put(seq->seq_exp);
344 CDEBUG(D_INFO|D_WARNING, "Client Sequence Manager\n");
348 EXPORT_SYMBOL(seq_client_fini);