Whamcloud - gitweb
update snapfs 1. fix bug in write table_count in write snap_table 2. fixbug in repla...
[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_print_entry = 1;
33 int snap_debug_level = 0;
34 int snap_inodes = 0;
35 long snap_kmemory = 0;
36 int snap_stack = 0;
37 struct snap_control_device snap_dev;
38
39 extern int snap_ioctl (struct inode * inode, struct file * filp, 
40                        unsigned int cmd, unsigned long arg);
41
42 /* called when opening /dev/device */
43 static int snap_psdev_open(struct inode * inode, struct file * file)
44 {
45         int dev;
46         ENTRY;
47
48         if (!inode)
49                 RETURN(-EINVAL);
50         dev = MINOR(inode->i_rdev);
51         if (dev != SNAP_PSDEV_MINOR)
52                 RETURN(-ENODEV);
53
54         RETURN(0);
55 }
56
57 /* called when closing /dev/device */
58 static int snap_psdev_release(struct inode * inode, struct file * file)
59 {
60         int dev;
61         ENTRY;
62
63         if (!inode)
64                 RETURN(-EINVAL);
65         dev = MINOR(inode->i_rdev);
66         if (dev != SNAP_PSDEV_MINOR)
67                 RETURN(-ENODEV);
68
69         RETURN(0);
70 }
71
72 /* XXX need ioctls here to do snap_delete and snap_restore, snap_backup */
73
74
75 /* declare character device */
76 static struct file_operations snapcontrol_fops = {
77         ioctl:          snap_ioctl,            /* ioctl */
78         open:           snap_psdev_open,       /* open */
79         release:        snap_psdev_release,    /* release */
80 };
81
82
83
84 #define SNAPFS_MINOR 240
85
86 static struct miscdevice snapcontrol_dev = {
87         minor:  SNAPFS_MINOR,
88         name:   "snapcontrol",
89         fops:   &snapcontrol_fops
90 };
91
92 int init_snap_psdev(void)
93 {
94         printk(KERN_INFO "SNAP psdev driver  v0.01, braam@clusterfs.com\n");
95         
96         misc_register( &snapcontrol_dev );
97
98         return 0;
99 }
100
101 void snap_cleanup_psdev(void)
102 {
103         ENTRY;
104         misc_deregister(&snapcontrol_dev);
105         EXIT;
106 }
107
108 MODULE_AUTHOR("Peter J. Braam <braam@cs.cmu.edu>");
109 MODULE_DESCRIPTION("Snapfs file system filters v0.01");
110
111 extern int init_snapfs(void);
112 extern int cleanup_snapfs(void);
113 extern int init_clonefs(void);
114 extern int init_snap_sysctl(void); 
115
116 static int __init snapfs_init(void)
117 {
118         int err;
119         if ( (err = init_snap_psdev()) ) {
120                 printk("Error initializing snap_psdev, %d\n", err);
121                 return -EINVAL;
122         }
123
124         if ( (err = init_snapfs()) ) {
125                 printk("Error initializing snapfs, %d\n", err);
126                 return -EINVAL;
127         }
128
129         if ( (err = init_snapfs_proc_sys()) ) {
130                 printk("Error initializing snapfs proc sys, %d\n", err);
131                 return -EINVAL;
132         }
133         
134         return 0;
135 }
136
137 static void __exit snapfs_cleanup(void)
138 {
139
140         cleanup_snapfs();
141         snap_cleanup_psdev();
142         
143 }
144 module_init(snapfs_init);
145 module_exit(snapfs_cleanup);
146                                                                                                                                                                                                      
147