Whamcloud - gitweb
ORNL-10: Basic IR implementation
[fs/lustre-release.git] / lustre / mgs / mgs_fs.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
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.
11  *
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).
17  *
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
21  *
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
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
30  * Use is subject to license terms.
31  *
32  * Copyright (c) 2011 Whamcloud, Inc.
33  *
34  */
35 /*
36  * This file is part of Lustre, http://www.lustre.org/
37  * Lustre is a trademark of Sun Microsystems, Inc.
38  *
39  * lustre/mgs/mgs_fs.c
40  *
41  * Lustre Management Server (MGS) filesystem interface code
42  *
43  * Author: Nathan Rutman <nathan@clusterfs.com>
44  */
45
46 #ifndef EXPORT_SYMTAB
47 # define EXPORT_SYMTAB
48 #endif
49 #define DEBUG_SUBSYSTEM S_MGS
50
51 #include <linux/module.h>
52 #include <linux/kmod.h>
53 #include <linux/version.h>
54 #include <linux/sched.h>
55 #include <linux/mount.h>
56 #include <obd_class.h>
57 #include <obd_support.h>
58 #include <lustre_disk.h>
59 #include <lustre_lib.h>
60 #include <lustre_fsfilt.h>
61 #include <libcfs/list.h>
62 #include "mgs_internal.h"
63
64 int mgs_export_stats_init(struct obd_device *obd, struct obd_export *exp,
65                           void *localdata)
66
67 {
68         lnet_nid_t *client_nid = localdata;
69         int rc, newnid;
70         ENTRY;
71
72         rc = lprocfs_exp_setup(exp, client_nid, &newnid);
73         if (rc) {
74                 /* Mask error for already created
75                  * /proc entries */
76                 if (rc == -EALREADY)
77                         rc = 0;
78                 RETURN(rc);
79         }
80         if (newnid) {
81                 struct nid_stat *tmp = exp->exp_nid_stats;
82                 int num_stats = 0;
83
84                 num_stats = (sizeof(*obd->obd_type->typ_dt_ops) / sizeof(void *)) +
85                             LPROC_MGS_LAST - 1;
86                 tmp->nid_stats = lprocfs_alloc_stats(num_stats,
87                                                      LPROCFS_STATS_FLAG_NOPERCPU);
88                 if (tmp->nid_stats == NULL)
89                         return -ENOMEM;
90                 lprocfs_init_ops_stats(LPROC_MGS_LAST, tmp->nid_stats);
91                 mgs_stats_counter_init(tmp->nid_stats);
92                 rc = lprocfs_register_stats(tmp->nid_proc, "stats",
93                                             tmp->nid_stats);
94                 if (rc)
95                         GOTO(clean, rc);
96
97                 rc = lprocfs_nid_ldlm_stats_init(tmp);
98                 if (rc)
99                         GOTO(clean, rc);
100         }
101         RETURN(0);
102 clean:
103         return rc;
104 }
105
106 /**
107  * Add client export data to the MGS.  This data is currently NOT stored on
108  * disk in the last_rcvd file or anywhere else.  In the event of a MGS
109  * crash all connections are treated as new connections.
110  */
111 int mgs_client_add(struct obd_device *obd, struct obd_export *exp,
112                    void *localdata)
113 {
114         return 0;
115 }
116
117 /* Remove client export data from the MGS */
118 int mgs_client_free(struct obd_export *exp)
119 {
120         return 0;
121 }
122
123 /* Same as mds_lvfs_fid2dentry */
124 /* Look up an entry by inode number. */
125 /* this function ONLY returns valid dget'd dentries with an initialized inode
126    or errors */
127 static struct dentry *mgs_lvfs_fid2dentry(__u64 id, __u32 gen,
128                                           __u64 gr, void *data)
129 {
130         struct fsfilt_fid  fid;
131         struct obd_device *obd = (struct obd_device *)data;
132         ENTRY;
133
134         CDEBUG(D_DENTRY, "--> mgs_fid2dentry: ino/gen %lu/%u, sb %p\n",
135                (unsigned long)id, gen, obd->u.mgs.mgs_sb);
136
137         if (id == 0)
138                 RETURN(ERR_PTR(-ESTALE));
139
140         fid.ino = id;
141         fid.gen = gen;
142
143         RETURN(fsfilt_fid2dentry(obd, obd->u.mgs.mgs_vfsmnt, &fid, 0));
144 }
145
146 struct lvfs_callback_ops mgs_lvfs_ops = {
147         l_fid2dentry:     mgs_lvfs_fid2dentry,
148 };
149
150 int mgs_fs_setup(struct obd_device *obd, struct vfsmount *mnt)
151 {
152         struct mgs_obd *mgs = &obd->u.mgs;
153         struct lvfs_run_ctxt saved;
154         struct dentry *dentry;
155         int rc;
156         ENTRY;
157
158         /* FIXME what's this?  Do I need it? */
159         rc = cfs_cleanup_group_info();
160         if (rc)
161                 RETURN(rc);
162
163         mgs->mgs_vfsmnt = mnt;
164         mgs->mgs_sb = mnt->mnt_root->d_inode->i_sb;
165
166         fsfilt_setup(obd, mgs->mgs_sb);
167
168         OBD_SET_CTXT_MAGIC(&obd->obd_lvfs_ctxt);
169         obd->obd_lvfs_ctxt.pwdmnt = mnt;
170         obd->obd_lvfs_ctxt.pwd = mnt->mnt_root;
171         obd->obd_lvfs_ctxt.fs = get_ds();
172         obd->obd_lvfs_ctxt.cb_ops = mgs_lvfs_ops;
173
174         push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
175
176         /* Setup the configs dir */
177         dentry = simple_mkdir(cfs_fs_pwd(current->fs), mnt, MOUNT_CONFIGS_DIR, 0777, 1);
178         if (IS_ERR(dentry)) {
179                 rc = PTR_ERR(dentry);
180                 CERROR("cannot create %s directory: rc = %d\n",
181                        MOUNT_CONFIGS_DIR, rc);
182                 GOTO(err_pop, rc);
183         }
184         mgs->mgs_configs_dir = dentry;
185
186         /* create directory to store nid table versions */
187         dentry = simple_mkdir(cfs_fs_pwd(current->fs), mnt, MGS_NIDTBL_DIR,
188                               0777, 1);
189         if (IS_ERR(dentry)) {
190                 rc = PTR_ERR(dentry);
191                 CERROR("cannot create %s directory: rc = %d\n",
192                        MOUNT_CONFIGS_DIR, rc);
193                 GOTO(err_pop, rc);
194         } else {
195                 dput(dentry);
196         }
197
198 err_pop:
199         pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
200         return rc;
201 }
202
203 int mgs_fs_cleanup(struct obd_device *obd)
204 {
205         struct mgs_obd *mgs = &obd->u.mgs;
206         struct lvfs_run_ctxt saved;
207         int rc = 0;
208
209         class_disconnect_exports(obd); /* cleans up client info too */
210
211         push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
212
213         if (mgs->mgs_configs_dir) {
214                 l_dput(mgs->mgs_configs_dir);
215                 mgs->mgs_configs_dir = NULL;
216         }
217
218         shrink_dcache_sb(mgs->mgs_sb);
219
220         pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
221
222         return rc;
223 }