Whamcloud - gitweb
b=24037 Remove iopen patch.
[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 /*
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  */
42
43 #ifndef EXPORT_SYMTAB
44 # define EXPORT_SYMTAB
45 #endif
46 #define DEBUG_SUBSYSTEM S_MGS
47
48 #include <linux/module.h>
49 #include <linux/kmod.h>
50 #include <linux/version.h>
51 #include <linux/sched.h>
52 #include <linux/mount.h>
53 #include <obd_class.h>
54 #include <obd_support.h>
55 #include <lustre_disk.h>
56 #include <lustre_lib.h>
57 #include <lustre_fsfilt.h>
58 #include <libcfs/list.h>
59 #include "mgs_internal.h"
60
61 int mgs_export_stats_init(struct obd_device *obd, struct obd_export *exp,
62                           int reconnect, void *localdata)
63
64 {
65         lnet_nid_t *client_nid = localdata;
66         int rc, newnid;
67         ENTRY;
68
69         rc = lprocfs_exp_setup(exp, client_nid, reconnect, &newnid);
70         if (rc) {
71                 /* Mask error for already created
72                  * /proc entries */
73                 if (rc == -EALREADY)
74                         rc = 0;
75                 RETURN(rc);
76         }
77         if (newnid) {
78                 struct nid_stat *tmp = exp->exp_nid_stats;
79                 int num_stats = 0;
80
81                 num_stats = (sizeof(*obd->obd_type->typ_dt_ops) / sizeof(void *)) +
82                             LPROC_MGS_LAST - 1;
83                 tmp->nid_stats = lprocfs_alloc_stats(num_stats,
84                                                      LPROCFS_STATS_FLAG_NOPERCPU);
85                 if (tmp->nid_stats == NULL)
86                         return -ENOMEM;
87                 lprocfs_init_ops_stats(LPROC_MGS_LAST, tmp->nid_stats);
88                 mgs_stats_counter_init(tmp->nid_stats);
89                 rc = lprocfs_register_stats(tmp->nid_proc, "stats",
90                                             tmp->nid_stats);
91                 if (rc)
92                         GOTO(clean, rc);
93
94                 rc = lprocfs_nid_ldlm_stats_init(tmp);
95                 if (rc)
96                         GOTO(clean, rc);
97         }
98         RETURN(0);
99 clean:
100         return rc;
101 }
102
103 /**
104  * Add client export data to the MGS.  This data is currently NOT stored on
105  * disk in the last_rcvd file or anywhere else.  In the event of a MGS
106  * crash all connections are treated as new connections.
107  */
108 int mgs_client_add(struct obd_device *obd, struct obd_export *exp,
109                    void *localdata)
110 {
111         return 0;
112 }
113
114 /* Remove client export data from the MGS */
115 int mgs_client_free(struct obd_export *exp)
116 {
117         return 0;
118 }
119
120 /* Same as mds_lvfs_fid2dentry */
121 /* Look up an entry by inode number. */
122 /* this function ONLY returns valid dget'd dentries with an initialized inode
123    or errors */
124 static struct dentry *mgs_lvfs_fid2dentry(__u64 id, __u32 gen,
125                                           __u64 gr, void *data)
126 {
127         struct fsfilt_fid  fid;
128         struct obd_device *obd = (struct obd_device *)data;
129         ENTRY;
130
131         CDEBUG(D_DENTRY, "--> mgs_fid2dentry: ino/gen %lu/%u, sb %p\n",
132                (unsigned long)id, gen, obd->u.mgs.mgs_sb);
133
134         if (id == 0)
135                 RETURN(ERR_PTR(-ESTALE));
136
137         fid.ino = id;
138         fid.gen = gen;
139
140         RETURN(fsfilt_fid2dentry(obd, obd->u.mgs.mgs_vfsmnt, &fid, 0));
141 }
142
143 struct lvfs_callback_ops mgs_lvfs_ops = {
144         l_fid2dentry:     mgs_lvfs_fid2dentry,
145 };
146
147 int mgs_fs_setup(struct obd_device *obd, struct vfsmount *mnt)
148 {
149         struct mgs_obd *mgs = &obd->u.mgs;
150         struct lvfs_run_ctxt saved;
151         struct dentry *dentry;
152         int rc;
153         ENTRY;
154
155         /* FIXME what's this?  Do I need it? */
156         rc = cfs_cleanup_group_info();
157         if (rc)
158                 RETURN(rc);
159
160         mgs->mgs_vfsmnt = mnt;
161         mgs->mgs_sb = mnt->mnt_root->d_inode->i_sb;
162
163         fsfilt_setup(obd, mgs->mgs_sb);
164
165         OBD_SET_CTXT_MAGIC(&obd->obd_lvfs_ctxt);
166         obd->obd_lvfs_ctxt.pwdmnt = mnt;
167         obd->obd_lvfs_ctxt.pwd = mnt->mnt_root;
168         obd->obd_lvfs_ctxt.fs = get_ds();
169         obd->obd_lvfs_ctxt.cb_ops = mgs_lvfs_ops;
170
171         push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
172
173         /* Setup the configs dir */
174         dentry = simple_mkdir(cfs_fs_pwd(current->fs), mnt, MOUNT_CONFIGS_DIR, 0777, 1);
175         if (IS_ERR(dentry)) {
176                 rc = PTR_ERR(dentry);
177                 CERROR("cannot create %s directory: rc = %d\n",
178                        MOUNT_CONFIGS_DIR, rc);
179                 GOTO(err_pop, rc);
180         }
181         mgs->mgs_configs_dir = dentry;
182
183 err_pop:
184         pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
185         return rc;
186 }
187
188 int mgs_fs_cleanup(struct obd_device *obd)
189 {
190         struct mgs_obd *mgs = &obd->u.mgs;
191         struct lvfs_run_ctxt saved;
192         int rc = 0;
193
194         class_disconnect_exports(obd); /* cleans up client info too */
195
196         push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
197
198         if (mgs->mgs_configs_dir) {
199                 l_dput(mgs->mgs_configs_dir);
200                 mgs->mgs_configs_dir = NULL;
201         }
202
203         shrink_dcache_sb(mgs->mgs_sb);
204
205         pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
206
207         return rc;
208 }