Whamcloud - gitweb
- a little bit more noise about read/write seq-mgr data to store.
[fs/lustre-release.git] / lustre / fid / fid_store.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  *  lustre/fid/fid_store.c
5  *  Lustre Sequence Manager
6  *
7  *  Copyright (c) 2006 Cluster File Systems, Inc.
8  *   Author: Yury Umanets <umka@clusterfs.com>
9  *
10  *   This file is part of the Lustre file system, http://www.lustre.org
11  *   Lustre is a trademark of Cluster File Systems, Inc.
12  *
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.
17  *
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.
22  *
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.
27  */
28
29 #ifndef EXPORT_SYMTAB
30 # define EXPORT_SYMTAB
31 #endif
32 #define DEBUG_SUBSYSTEM S_FID
33
34 #ifdef __KERNEL__
35 # include <libcfs/libcfs.h>
36 # include <linux/module.h>
37 #else /* __KERNEL__ */
38 # include <liblustre.h>
39 #endif
40
41 #include <obd.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"
49
50 #ifdef __KERNEL__
51 enum {
52         SEQ_TXN_STORE_CREDITS = 20
53 };
54
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)
58 {
59         struct dt_object *dt_obj = seq->lss_obj;
60         struct seq_thread_info *info;
61         struct dt_device *dt_dev;
62         struct thandle *th;
63         loff_t pos = 0;
64         int rc;
65         ENTRY;
66
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);
70
71         /* stub here, will fix it later */
72         info->sti_txn.tp_credits = SEQ_TXN_STORE_CREDITS;
73
74         th = dt_dev->dd_ops->dt_trans_start(ctx, dt_dev, &info->sti_txn);
75         if (!IS_ERR(th)) {
76                 /* store ranges in le format */
77                 range_cpu_to_le(&info->sti_record.ssr_space, &seq->lss_space);
78                 range_cpu_to_le(&info->sti_record.ssr_super, &seq->lss_super);
79  
80                 rc = dt_obj->do_body_ops->dbo_write(ctx, dt_obj,
81                                                     (char *)&info->sti_record,
82                                                     sizeof(info->sti_record),
83                                                     &pos, th);
84                 if (rc == sizeof(info->sti_record)) {
85                         CDEBUG(D_INFO|D_WARNING, "store %s ranges: space - "
86                                DRANGE", super - "DRANGE"\n",
87                                (seq->lss_type == LUSTRE_SEQ_SERVER ?
88                                 "server" : "controller"),
89                                PRANGE(&seq->lss_space), PRANGE(&seq->lss_super));
90
91                         rc = 0;
92                 } else if (rc >= 0) {
93                         rc = -EIO;
94                 }
95                 
96                 dt_dev->dd_ops->dt_trans_stop(ctx, th);
97         } else {
98                 rc = PTR_ERR(th);
99         }
100         
101         RETURN(rc);
102 }
103
104 /* this function implies that caller takes care about locking or locking is not
105  * needed (init time). */
106 int seq_store_read(struct lu_server_seq *seq,
107                    const struct lu_context *ctx)
108 {
109         struct dt_object *dt_obj = seq->lss_obj;
110         struct seq_thread_info *info;
111         loff_t pos = 0;
112         int rc;
113         ENTRY;
114
115         info = lu_context_key_get(ctx, &seq_thread_key);
116         LASSERT(info != NULL);
117
118         rc = dt_obj->do_body_ops->dbo_read(ctx, dt_obj,
119                                            (char *)&info->sti_record,
120                                            sizeof(info->sti_record), &pos);
121         
122         if (rc == sizeof(info->sti_record)) {
123                 range_le_to_cpu(&seq->lss_space, &info->sti_record.ssr_space);
124                 range_le_to_cpu(&seq->lss_super, &info->sti_record.ssr_super);
125
126                 CDEBUG(D_INFO|D_WARNING, "read %s ranges: space - "DRANGE", super "
127                        "- "DRANGE"\n", (seq->lss_type == LUSTRE_SEQ_SERVER ?
128                                         "server" : "controller"),
129                        PRANGE(&seq->lss_space), PRANGE(&seq->lss_super));
130                 rc = 0;
131         } else if (rc == 0) {
132                 rc = -ENODATA;
133         } else if (rc >= 0) {
134                 CERROR("read only %d bytes of %d\n", rc, sizeof(info->sti_record));
135                 rc = -EIO;
136         }
137         
138         RETURN(rc);
139 }
140
141 int seq_store_init(struct lu_server_seq *seq,
142                    const struct lu_context *ctx,
143                    struct dt_device *dt)
144 {
145         struct dt_object *dt_obj;
146         struct lu_fid fid;
147         const char *name;
148         int rc;
149         ENTRY;
150
151         name = seq->lss_type == LUSTRE_SEQ_SERVER ?
152                 "seq_srv" : "seq_ctl";
153         
154         dt_obj = dt_store_open(ctx, dt, name, &fid);
155         if (!IS_ERR(dt_obj)) {
156                 seq->lss_obj = dt_obj;
157                 rc = 0;
158         } else {
159                 CERROR("cannot find \"seq\" obj %d\n",
160                        (int)PTR_ERR(dt_obj));
161                 rc = PTR_ERR(dt_obj);
162         }
163
164         RETURN(rc);
165 }
166
167 void seq_store_fini(struct lu_server_seq *seq,
168                     const struct lu_context *ctx)
169 {
170         ENTRY;
171
172         if (seq->lss_obj != NULL) {
173                 if (!IS_ERR(seq->lss_obj))
174                         lu_object_put(ctx, &seq->lss_obj->do_lu);
175                 seq->lss_obj = NULL;
176         }
177         
178         EXIT;
179 }
180 #endif