Whamcloud - gitweb
b=3031
[fs/lustre-release.git] / lustre / snapfs / psdev.c
1 /*
2  *              A file system filter driver in the style of InterMezzo
3  *              to manage file system snapshots
4  *
5  *              Author:  Peter J. Braam <braam@mountainviewdata.com>
6  *
7  *              This program is free software; you can redistribute it and/or
8  *              modify it under the terms of the GNU General Public License
9  *              as published by the Free Software Foundation; either version
10  *              2 of the License, or (at your option) any later version.
11  */
12
13 #define EXPORT_SYMTAB
14
15
16 #define DEBUG_SUBSYSTEM S_SNAP
17
18 #include <linux/module.h>
19 #include <linux/kernel.h>
20 #include <linux/string.h>
21 #include <linux/slab.h>
22 #include <linux/stat.h>
23 #include <linux/unistd.h>
24 #include <linux/miscdevice.h>
25 #include <linux/jbd.h>
26 #include <linux/ext3_fs.h>
27 #include <linux/snap.h>
28
29 #include "snapfs_internal.h" 
30
31
32 int snap_inodes = 0;
33 long snap_kmemory = 0;
34 int snap_stack = 0;
35 struct snap_control_device snap_dev;
36
37 extern int snap_ioctl (struct inode * inode, struct file * filp, 
38                        unsigned int cmd, unsigned long arg);
39
40 /* called when opening /dev/device */
41 static int snap_psdev_open(struct inode * inode, struct file * file)
42 {
43         int dev;
44         ENTRY;
45
46         if (!inode)
47                 RETURN(-EINVAL);
48         dev = MINOR(inode->i_rdev);
49         if (dev != SNAP_PSDEV_MINOR)
50                 RETURN(-ENODEV);
51
52         RETURN(0);
53 }
54
55 /* called when closing /dev/device */
56 static int snap_psdev_release(struct inode * inode, struct file * file)
57 {
58         int dev;
59         ENTRY;
60
61         if (!inode)
62                 RETURN(-EINVAL);
63         dev = MINOR(inode->i_rdev);
64         if (dev != SNAP_PSDEV_MINOR)
65                 RETURN(-ENODEV);
66
67         RETURN(0);
68 }
69
70 /* XXX need ioctls here to do snap_delete and snap_restore, snap_backup */
71
72
73 /* declare character device */
74 static struct file_operations snapcontrol_fops = {
75         ioctl:          snap_ioctl,            /* ioctl */
76         open:           snap_psdev_open,       /* open */
77         release:        snap_psdev_release,    /* release */
78 };
79
80
81
82 #define SNAPFS_MINOR 240
83
84 static struct miscdevice snapcontrol_dev = {
85         minor:  SNAPFS_MINOR,
86         name:   "snapcontrol",
87         fops:   &snapcontrol_fops
88 };
89
90 int init_snap_psdev(void)
91 {
92         printk(KERN_INFO "SNAP psdev driver  v0.01, braam@clusterfs.com\n");
93         
94         misc_register( &snapcontrol_dev );
95
96         return 0;
97 }
98
99 void snap_cleanup_psdev(void)
100 {
101         ENTRY;
102         misc_deregister(&snapcontrol_dev);
103         EXIT;
104 }
105
106 MODULE_AUTHOR("Peter J. Braam <braam@cs.cmu.edu>");
107 MODULE_DESCRIPTION("Snapfs file system filters v0.01");
108
109 extern int init_snapfs(void);
110 extern int cleanup_snapfs(void);
111 extern int init_clonefs(void);
112 extern int init_snap_sysctl(void); 
113
114 static int __init snapfs_init(void)
115 {
116         int err;
117         if ( (err = init_snap_psdev()) ) {
118                 printk("Error initializing snap_psdev, %d\n", err);
119                 return -EINVAL;
120         }
121
122         if ( (err = init_snapfs()) ) {
123                 printk("Error initializing snapfs, %d\n", err);
124                 return -EINVAL;
125         }
126
127         if ( (err = init_snapfs_proc_sys()) ) {
128                 printk("Error initializing snapfs proc sys, %d\n", err);
129                 return -EINVAL;
130         }
131         
132         return 0;
133 }
134
135 static void __exit snapfs_cleanup(void)
136 {
137
138         cleanup_snapfs();
139         snap_cleanup_psdev();
140         
141 }
142 module_init(snapfs_init);
143 module_exit(snapfs_cleanup);
144                                                                                                                                                                                                      
145