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/lvfs.h>
31 struct dentry *lvfs_id2dentry(struct lvfs_run_ctxt *ctxt, __u64 id,
32 __u32 gen, __u64 gr, void *data)
34 return ctxt->cb_ops.l_id2dentry(id, gen, gr, data);
36 EXPORT_SYMBOL(lvfs_id2dentry);
38 static struct list_head lvfs_context_list;
40 void lvfs_mount_list_init(void)
42 INIT_LIST_HEAD(&lvfs_context_list);
45 void lvfs_mount_list_cleanup(void)
47 struct list_head *tmp;
49 if (list_empty(&lvfs_context_list))
52 list_for_each(tmp, &lvfs_context_list) {
53 struct lvfs_obd_ctxt *data =
54 list_entry(tmp, struct lvfs_obd_ctxt, loc_list);
55 CERROR("device %s still mounted with refcount %d\n",
56 data->loc_name, atomic_read(&data->loc_refcount));
61 struct lvfs_obd_ctxt *get_lvfs_mount(struct lvfs_obd_ctxt *lvfs_ctxt)
63 atomic_inc(&lvfs_ctxt->loc_refcount);
67 static struct lvfs_obd_ctxt *add_lvfs_mount(struct vfsmount *mnt, char *name)
69 struct lvfs_obd_ctxt *lvfs_ctxt;
72 OBD_ALLOC(lvfs_ctxt, sizeof(*lvfs_ctxt));
74 CERROR("No Memory\n");
79 int length = strlen(name) + 1;
81 OBD_ALLOC(lvfs_ctxt->loc_name, length);
82 if (!lvfs_ctxt->loc_name) {
83 CERROR("No Memory\n");
84 OBD_FREE(lvfs_ctxt, sizeof(*lvfs_ctxt));
87 memcpy(lvfs_ctxt->loc_name, name, length);
89 lvfs_ctxt->loc_mnt = mnt;
90 list_add(&lvfs_ctxt->loc_list, &lvfs_context_list);
91 atomic_set(&lvfs_ctxt->loc_refcount, 1);
95 void lvfs_umount_fs(struct lvfs_obd_ctxt *lvfs_ctxt)
97 if (lvfs_ctxt && atomic_dec_and_test(&lvfs_ctxt->loc_refcount)) {
98 struct vfsmount *mnt = lvfs_ctxt->loc_mnt;
100 list_del(&lvfs_ctxt->loc_list);
101 if (atomic_read(&mnt->mnt_count) > 2)
102 CERROR("mount busy, mnt %p mnt_count %d != 2\n", mnt,
103 atomic_read(&mnt->mnt_count));
107 if (lvfs_ctxt->loc_name)
108 OBD_FREE(lvfs_ctxt->loc_name,
109 strlen(lvfs_ctxt->loc_name) + 1);
110 OBD_FREE(lvfs_ctxt, sizeof(*lvfs_ctxt));
114 EXPORT_SYMBOL(lvfs_umount_fs);
116 int lvfs_mount_fs(char *name, char *fstype, char *options, int flags,
117 struct lvfs_obd_ctxt **lvfs_ctxt)
119 struct vfsmount *mnt = NULL;
120 struct list_head *tmp;
124 list_for_each(tmp, &lvfs_context_list) {
125 struct lvfs_obd_ctxt *data =
126 list_entry(tmp, struct lvfs_obd_ctxt, loc_list);
127 if (strcmp(data->loc_name, name) == 0) {
128 *lvfs_ctxt = get_lvfs_mount(data);
132 mnt = do_kern_mount(fstype, flags, name, options);
136 CERROR("do_kern_mount failed: rc = %d\n", rc);
139 CDEBUG(D_SUPER, "%s: mnt = %p\n", name, mnt);
140 /*add this lvfs context to the lvfs_mount_list*/
141 *lvfs_ctxt = add_lvfs_mount(mnt, name);
144 CERROR("add_lvfs_mount failed\n");
145 GOTO(out, rc = -EINVAL);
150 EXPORT_SYMBOL(lvfs_mount_fs);