Whamcloud - gitweb
e621bf0d5f25940d47c2ba83b4e5366c15acc5c9
[fs/lustre-release.git] / lustre / mgs / mgs_fs.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, 2012, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lustre/mgs/mgs_fs.c
37  *
38  * Lustre Management Server (MGS) filesystem interface code
39  *
40  * Author: Nathan Rutman <nathan@clusterfs.com>
41  * Author: Alex Zhuravlev <bzzz@whamcloud.com>
42  */
43
44 #define DEBUG_SUBSYSTEM S_MGS
45
46 #include <lustre_fid.h>
47 #include "mgs_internal.h"
48
49 int mgs_export_stats_init(struct obd_device *obd, struct obd_export *exp,
50                           void *localdata)
51
52 {
53         lnet_nid_t *client_nid = localdata;
54         int rc, newnid;
55         ENTRY;
56
57         rc = lprocfs_exp_setup(exp, client_nid, &newnid);
58         if (rc) {
59                 /* Mask error for already created
60                  * /proc entries */
61                 if (rc == -EALREADY)
62                         rc = 0;
63                 RETURN(rc);
64         }
65         if (newnid) {
66                 struct nid_stat *tmp = exp->exp_nid_stats;
67                 int num_stats = 0;
68
69                 num_stats = (sizeof(*obd->obd_type->typ_dt_ops) / sizeof(void *)) +
70                             LPROC_MGS_LAST - 1;
71                 tmp->nid_stats = lprocfs_alloc_stats(num_stats,
72                                                      LPROCFS_STATS_FLAG_NOPERCPU);
73                 if (tmp->nid_stats == NULL)
74                         return -ENOMEM;
75                 lprocfs_init_ops_stats(LPROC_MGS_LAST, tmp->nid_stats);
76                 mgs_stats_counter_init(tmp->nid_stats);
77                 rc = lprocfs_register_stats(tmp->nid_proc, "stats",
78                                             tmp->nid_stats);
79                 if (rc)
80                         GOTO(clean, rc);
81
82                 rc = lprocfs_nid_ldlm_stats_init(tmp);
83                 if (rc)
84                         GOTO(clean, rc);
85         }
86         RETURN(0);
87 clean:
88         return rc;
89 }
90
91 /**
92  * Add client export data to the MGS.  This data is currently NOT stored on
93  * disk in the last_rcvd file or anywhere else.  In the event of a MGS
94  * crash all connections are treated as new connections.
95  */
96 int mgs_client_add(struct obd_device *obd, struct obd_export *exp,
97                    void *localdata)
98 {
99         return 0;
100 }
101
102 /* Remove client export data from the MGS */
103 int mgs_client_free(struct obd_export *exp)
104 {
105         return 0;
106 }
107
108 int mgs_fs_setup(const struct lu_env *env, struct mgs_device *mgs)
109 {
110         struct lu_fid            fid;
111         struct dt_object        *o;
112         struct lu_fid            rfid;
113         struct dt_object        *root;
114         int                      rc;
115
116         ENTRY;
117
118         /* FIXME what's this?  Do I need it? */
119         rc = cfs_cleanup_group_info();
120         if (rc)
121                 RETURN(rc);
122
123         OBD_SET_CTXT_MAGIC(&mgs->mgs_obd->obd_lvfs_ctxt);
124         mgs->mgs_obd->obd_lvfs_ctxt.dt = mgs->mgs_bottom;
125
126         /* XXX: fix when support for N:1 layering is implemented */
127         LASSERT(mgs->mgs_dt_dev.dd_lu_dev.ld_site);
128         mgs->mgs_dt_dev.dd_lu_dev.ld_site->ls_top_dev =
129                 &mgs->mgs_dt_dev.dd_lu_dev;
130
131         /* Setup the configs dir */
132         fid.f_seq = FID_SEQ_LOCAL_NAME;
133         fid.f_oid = 1;
134         fid.f_ver = 0;
135         rc = local_oid_storage_init(env, mgs->mgs_bottom, &fid, &mgs->mgs_los);
136         if (rc)
137                 GOTO(out, rc);
138
139         rc = dt_root_get(env, mgs->mgs_bottom, &rfid);
140         if (rc)
141                 GOTO(out_los, rc);
142
143         root = dt_locate_at(env, mgs->mgs_bottom, &rfid,
144                             &mgs->mgs_dt_dev.dd_lu_dev);
145         if (unlikely(IS_ERR(root)))
146                 GOTO(out_los, rc = PTR_ERR(root));
147
148         o = local_file_find_or_create(env, mgs->mgs_los, root,
149                                       MOUNT_CONFIGS_DIR,
150                                       S_IFDIR | S_IRUGO | S_IWUSR | S_IXUGO);
151         if (IS_ERR(o))
152                 GOTO(out_root, rc = PTR_ERR(o));
153
154         mgs->mgs_configs_dir = o;
155
156         /* create directory to store nid table versions */
157         o = local_file_find_or_create(env, mgs->mgs_los, root, MGS_NIDTBL_DIR,
158                                       S_IFDIR | S_IRUGO | S_IWUSR | S_IXUGO);
159         if (IS_ERR(o)) {
160                 lu_object_put(env, &mgs->mgs_configs_dir->do_lu);
161                 mgs->mgs_configs_dir = NULL;
162                 GOTO(out_root, rc = PTR_ERR(o));
163         }
164
165         mgs->mgs_nidtbl_dir = o;
166
167 out_root:
168         lu_object_put(env, &root->do_lu);
169 out_los:
170         if (rc) {
171                 local_oid_storage_fini(env, mgs->mgs_los);
172                 mgs->mgs_los = NULL;
173         }
174 out:
175         mgs->mgs_dt_dev.dd_lu_dev.ld_site->ls_top_dev = NULL;
176
177         return rc;
178 }
179
180 int mgs_fs_cleanup(const struct lu_env *env, struct mgs_device *mgs)
181 {
182         class_disconnect_exports(mgs->mgs_obd); /* cleans up client info too */
183
184         if (mgs->mgs_configs_dir) {
185                 lu_object_put(env, &mgs->mgs_configs_dir->do_lu);
186                 mgs->mgs_configs_dir = NULL;
187         }
188         if (mgs->mgs_nidtbl_dir) {
189                 lu_object_put(env, &mgs->mgs_nidtbl_dir->do_lu);
190                 mgs->mgs_nidtbl_dir = NULL;
191         }
192         if (mgs->mgs_los) {
193                 local_oid_storage_fini(env, mgs->mgs_los);
194                 mgs->mgs_los = NULL;
195         }
196
197         return 0;
198 }