1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (c) 2003 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.lustre.org/
8 * Lustre is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Lustre; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 # define EXPORT_SYMTAB
26 #define DEBUG_SUBSYSTEM S_FILTER
28 #include <linux/obd.h>
29 #include <linux/obd_support.h>
30 #include <linux/lvfs.h>
32 struct dentry *lvfs_id2dentry(struct lvfs_run_ctxt *ctxt, __u64 id,
33 __u32 gen, __u64 gr, void *data)
35 return ctxt->cb_ops.l_id2dentry(id, gen, gr, data);
37 EXPORT_SYMBOL(lvfs_id2dentry);
39 static struct list_head lvfs_context_list;
41 void lvfs_mount_list_init(void)
43 INIT_LIST_HEAD(&lvfs_context_list);
46 void lvfs_mount_list_cleanup(void)
48 struct list_head *tmp;
50 if (list_empty(&lvfs_context_list))
53 list_for_each(tmp, &lvfs_context_list) {
54 struct lvfs_obd_ctxt *data =
55 list_entry(tmp, struct lvfs_obd_ctxt, loc_list);
56 CERROR("device %s still mounted with refcount %d\n",
57 data->loc_name, atomic_read(&data->loc_refcount));
62 struct lvfs_obd_ctxt *get_lvfs_mount(struct lvfs_obd_ctxt *lvfs_ctxt)
64 atomic_inc(&lvfs_ctxt->loc_refcount);
68 static struct lvfs_obd_ctxt *add_lvfs_mount(struct vfsmount *mnt, char *name)
70 struct lvfs_obd_ctxt *lvfs_ctxt;
73 OBD_ALLOC(lvfs_ctxt, sizeof(*lvfs_ctxt));
75 CERROR("No Memory\n");
80 int length = strlen(name) + 1;
82 OBD_ALLOC(lvfs_ctxt->loc_name, length);
83 if (!lvfs_ctxt->loc_name) {
84 CERROR("No Memory\n");
85 OBD_FREE(lvfs_ctxt, sizeof(*lvfs_ctxt));
88 memcpy(lvfs_ctxt->loc_name, name, length);
90 lvfs_ctxt->loc_mnt = mnt;
91 list_add(&lvfs_ctxt->loc_list, &lvfs_context_list);
92 atomic_set(&lvfs_ctxt->loc_refcount, 1);
96 void lvfs_umount_fs(struct lvfs_obd_ctxt *lvfs_ctxt)
98 if (lvfs_ctxt && atomic_dec_and_test(&lvfs_ctxt->loc_refcount)) {
99 struct vfsmount *mnt = lvfs_ctxt->loc_mnt;
100 ll_sbdev_type save_dev = ll_sbdev(mnt->mnt_sb);
102 list_del(&lvfs_ctxt->loc_list);
103 if (atomic_read(&mnt->mnt_count) > 2)
104 CERROR("mount busy, mnt %p mnt_count %d != 2\n", mnt,
105 atomic_read(&mnt->mnt_count));
108 if (lvfs_ctxt->loc_name)
109 OBD_FREE(lvfs_ctxt->loc_name,
110 strlen(lvfs_ctxt->loc_name) + 1);
111 OBD_FREE(lvfs_ctxt, sizeof(*lvfs_ctxt));
112 ll_clear_rdonly(save_dev);
115 EXPORT_SYMBOL(lvfs_umount_fs);
117 int lvfs_mount_fs(char *name, char *fstype, char *options, int flags,
118 struct lvfs_obd_ctxt **lvfs_ctxt)
120 struct vfsmount *mnt = NULL;
121 struct list_head *tmp;
125 list_for_each(tmp, &lvfs_context_list) {
126 struct lvfs_obd_ctxt *data =
127 list_entry(tmp, struct lvfs_obd_ctxt, loc_list);
128 if (strcmp(data->loc_name, name) == 0) {
129 *lvfs_ctxt = get_lvfs_mount(data);
133 mnt = do_kern_mount(fstype, flags, name, options);
137 CERROR("do_kern_mount failed: rc = %d\n", rc);
140 CDEBUG(D_SUPER, "%s: mnt = %p\n", name, mnt);
141 /*add this lvfs context to the lvfs_mount_list*/
142 *lvfs_ctxt = add_lvfs_mount(mnt, name);
145 CERROR("add_lvfs_mount failed\n");
146 GOTO(out, rc = -EINVAL);
151 EXPORT_SYMBOL(lvfs_mount_fs);