1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
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
29 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
32 * Copyright (c) 2011, Whamcloud, Inc.
35 * This file is part of Lustre, http://www.lustre.org/
36 * Lustre is a trademark of Sun Microsystems, Inc.
40 * Lustre Management Server (MGS) filesystem interface code
42 * Author: Nathan Rutman <nathan@clusterfs.com>
46 # define EXPORT_SYMTAB
48 #define DEBUG_SUBSYSTEM S_MGS
50 #include <linux/module.h>
51 #include <linux/kmod.h>
52 #include <linux/version.h>
53 #include <linux/sched.h>
54 #include <linux/mount.h>
55 #include <obd_class.h>
56 #include <obd_support.h>
57 #include <lustre_disk.h>
58 #include <lustre_lib.h>
59 #include <lustre_fsfilt.h>
60 #include <libcfs/list.h>
61 #include "mgs_internal.h"
63 int mgs_export_stats_init(struct obd_device *obd, struct obd_export *exp,
67 lnet_nid_t *client_nid = localdata;
71 rc = lprocfs_exp_setup(exp, client_nid, &newnid);
73 /* Mask error for already created
80 struct nid_stat *tmp = exp->exp_nid_stats;
83 num_stats = (sizeof(*obd->obd_type->typ_dt_ops) / sizeof(void *)) +
85 tmp->nid_stats = lprocfs_alloc_stats(num_stats,
86 LPROCFS_STATS_FLAG_NOPERCPU);
87 if (tmp->nid_stats == NULL)
89 lprocfs_init_ops_stats(LPROC_MGS_LAST, tmp->nid_stats);
90 mgs_stats_counter_init(tmp->nid_stats);
91 rc = lprocfs_register_stats(tmp->nid_proc, "stats",
96 rc = lprocfs_nid_ldlm_stats_init(tmp);
106 * Add client export data to the MGS. This data is currently NOT stored on
107 * disk in the last_rcvd file or anywhere else. In the event of a MGS
108 * crash all connections are treated as new connections.
110 int mgs_client_add(struct obd_device *obd, struct obd_export *exp,
116 /* Remove client export data from the MGS */
117 int mgs_client_free(struct obd_export *exp)
122 /* Same as mds_lvfs_fid2dentry */
123 /* Look up an entry by inode number. */
124 /* this function ONLY returns valid dget'd dentries with an initialized inode
126 static struct dentry *mgs_lvfs_fid2dentry(__u64 id, __u32 gen,
127 __u64 gr, void *data)
129 struct fsfilt_fid fid;
130 struct obd_device *obd = (struct obd_device *)data;
133 CDEBUG(D_DENTRY, "--> mgs_fid2dentry: ino/gen %lu/%u, sb %p\n",
134 (unsigned long)id, gen, obd->u.mgs.mgs_sb);
137 RETURN(ERR_PTR(-ESTALE));
142 RETURN(fsfilt_fid2dentry(obd, obd->u.mgs.mgs_vfsmnt, &fid, 0));
145 struct lvfs_callback_ops mgs_lvfs_ops = {
146 l_fid2dentry: mgs_lvfs_fid2dentry,
149 int mgs_fs_setup(struct obd_device *obd, struct vfsmount *mnt)
151 struct mgs_obd *mgs = &obd->u.mgs;
152 struct lvfs_run_ctxt saved;
153 struct dentry *dentry;
157 /* FIXME what's this? Do I need it? */
158 rc = cfs_cleanup_group_info();
162 mgs->mgs_vfsmnt = mnt;
163 mgs->mgs_sb = mnt->mnt_root->d_inode->i_sb;
165 fsfilt_setup(obd, mgs->mgs_sb);
167 OBD_SET_CTXT_MAGIC(&obd->obd_lvfs_ctxt);
168 obd->obd_lvfs_ctxt.pwdmnt = mnt;
169 obd->obd_lvfs_ctxt.pwd = mnt->mnt_root;
170 obd->obd_lvfs_ctxt.fs = get_ds();
171 obd->obd_lvfs_ctxt.cb_ops = mgs_lvfs_ops;
173 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
175 /* Setup the configs dir */
176 dentry = simple_mkdir(cfs_fs_pwd(current->fs), mnt, MOUNT_CONFIGS_DIR, 0777, 1);
177 if (IS_ERR(dentry)) {
178 rc = PTR_ERR(dentry);
179 CERROR("cannot create %s directory: rc = %d\n",
180 MOUNT_CONFIGS_DIR, rc);
183 mgs->mgs_configs_dir = dentry;
185 /* create directory to store nid table versions */
186 dentry = simple_mkdir(cfs_fs_pwd(current->fs), mnt, MGS_NIDTBL_DIR,
188 if (IS_ERR(dentry)) {
189 rc = PTR_ERR(dentry);
190 CERROR("cannot create %s directory: rc = %d\n",
191 MOUNT_CONFIGS_DIR, rc);
198 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
202 int mgs_fs_cleanup(struct obd_device *obd)
204 struct mgs_obd *mgs = &obd->u.mgs;
205 struct lvfs_run_ctxt saved;
208 class_disconnect_exports(obd); /* cleans up client info too */
210 push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
212 if (mgs->mgs_configs_dir) {
213 l_dput(mgs->mgs_configs_dir);
214 mgs->mgs_configs_dir = NULL;
217 shrink_dcache_sb(mgs->mgs_sb);
219 pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);