1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
5 * Lustre filesystem abstraction routines
7 * Copyright (C) 2004 Cluster File Systems, Inc.
9 * This file is part of Lustre, http://www.lustre.org.
11 * Lustre is free software; you can redistribute it and/or
12 * modify it under the terms of version 2 of the GNU General Public
13 * License as published by the Free Software Foundation.
15 * Lustre is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with Lustre; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #define DEBUG_SUBSYSTEM S_SM
30 #include <linux/module.h>
31 #include <linux/kernel.h>
32 #include <linux/string.h>
33 #include <linux/slab.h>
34 #include <linux/stat.h>
35 #include <linux/unistd.h>
36 #include <linux/miscdevice.h>
37 #include <linux/obd_class.h>
38 #include <linux/obd_support.h>
39 #include <linux/lustre_lib.h>
40 #include <linux/lustre_idl.h>
41 #include <linux/lustre_fsfilt.h>
42 #include <linux/lustre_mds.h>
43 #include <linux/lustre_debug.h>
44 #include <linux/lustre_smfs.h>
45 #include <linux/lustre_snap.h>
47 #include "smfs_internal.h"
49 static struct super_block *smfs_get_sb_by_path(char *path, int len)
51 struct super_block *sb;
55 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
56 if (path_init(path, LOOKUP_FOLLOW, &nd)) {
57 error = path_walk(path, &nd);
66 if (path_lookup(path, LOOKUP_FOLLOW, &nd))
70 /* FIXME-WANGDI: add some check code here. */
76 struct smfs_control_device smfs_dev;
78 static int smfs_handle_ioctl(unsigned int cmd, unsigned long arg)
80 struct obd_ioctl_data *data = NULL;
81 struct super_block *sb = NULL;
85 if (obd_ioctl_getdata(&buf, &len, (void *)arg)) {
86 CERROR("OBD ioctl: data error\n");
87 GOTO(out, err = -EINVAL);
89 data = (struct obd_ioctl_data *)buf;
92 case OBD_IOC_SMFS_SNAP_ADD:{
93 char *name, *snapshot_name;
94 if (!data->ioc_inllen1 || !data->ioc_inlbuf1) {
95 CERROR("No mountpoint passed!\n");
96 GOTO(out, err = -EINVAL);
98 if (!data->ioc_inllen2 || !data->ioc_inlbuf2) {
99 CERROR("No snapshotname passed!\n");
100 GOTO(out, err = -EINVAL);
102 name = (char*) data->ioc_inlbuf1;
103 sb = smfs_get_sb_by_path(name, data->ioc_inllen1);
105 CERROR("can not find superblock at %s\n", buf);
106 GOTO(out, err = -EINVAL);
108 snapshot_name = (char *)data->ioc_inlbuf2;
110 err = smfs_add_snap_item(sb, name, snapshot_name);
115 CERROR("The command passed in is Invalid\n");
116 GOTO(out, err = -EINVAL);
121 obd_ioctl_freedata(buf, len);
124 #define SMFS_MINOR 250
125 static int smfs_psdev_ioctl(struct inode * inode, struct file * filp,
126 unsigned int cmd, unsigned long arg)
129 rc = smfs_handle_ioctl(cmd, arg);
133 /* called when opening /dev/device */
134 static int smfs_psdev_open(struct inode * inode, struct file * file)
141 dev = MINOR(inode->i_rdev);
142 if (dev != SMFS_MINOR)
148 /* called when closing /dev/device */
149 static int smfs_psdev_release(struct inode * inode, struct file * file)
156 dev = MINOR(inode->i_rdev);
157 if (dev != SMFS_MINOR)
163 /* declare character device */
164 static struct file_operations smfscontrol_fops = {
165 .owner = THIS_MODULE,
166 .ioctl = smfs_psdev_ioctl, /* ioctl */
167 .open = smfs_psdev_open, /* open */
168 .release = smfs_psdev_release, /* release */
170 static struct miscdevice smfscontrol_dev = {
173 fops: &smfscontrol_fops
176 int init_smfs_psdev(void)
178 printk(KERN_INFO "SMFS psdev driver v0.01, braam@clusterfs.com\n");
180 misc_register(&smfscontrol_dev);
185 void smfs_cleanup_psdev(void)
188 misc_deregister(&smfscontrol_dev);