Whamcloud - gitweb
add snapfs to cvs
[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 #include <linux/config.h> /* for CONFIG_PROC_FS */
16 #include <linux/module.h>
17 #include <linux/errno.h>
18 #include <linux/kernel.h>
19 #include <linux/major.h>
20 /* #include <linux/kmod.h>    for request_module() */
21 #include <linux/sched.h>
22 #include <linux/lp.h>
23 #include <linux/malloc.h>
24 #include <linux/ioport.h>
25 #include <linux/fcntl.h>
26 #include <linux/delay.h>
27 #include <linux/skbuff.h>
28 #include <linux/proc_fs.h>
29 #include <linux/vmalloc.h>
30 #include <linux/fs.h>
31 #include <linux/poll.h>
32 #include <linux/init.h>
33 #include <linux/list.h>
34 #include <asm/io.h>
35 #include <asm/segment.h>
36 #include <asm/system.h>
37 #include <asm/poll.h>
38 #include <asm/uaccess.h>
39 #include <linux/miscdevice.h>
40
41 #include <linux/filter.h>
42 #include <linux/snapfs.h>
43 #include <linux/snapsupport.h>
44
45 #if 1 /* XXX - enable for debug messages */
46 int snap_print_entry = 1;
47 int snap_debug_level = ~D_INFO;
48 #else
49 int snap_print_entry = 0;
50 int snap_debug_level = 0;
51 #endif
52 int snap_inodes = 0;
53 long snap_memory = 0;
54
55 struct snap_control_device snap_dev;
56
57 extern int snap_ioctl (struct inode * inode, struct file * filp, 
58                        unsigned int cmd, unsigned long arg);
59
60 /* called when opening /dev/device */
61 static int snap_psdev_open(struct inode * inode, struct file * file)
62 {
63         int dev;
64         ENTRY;
65
66         if (!inode)
67                 return -EINVAL;
68         dev = MINOR(inode->i_rdev);
69         if (dev != SNAP_PSDEV_MINOR)
70                 return -ENODEV;
71
72         MOD_INC_USE_COUNT;
73         EXIT;
74         return 0;
75 }
76
77 /* called when closing /dev/device */
78 static int snap_psdev_release(struct inode * inode, struct file * file)
79 {
80         int dev;
81         ENTRY;
82
83         if (!inode)
84                 return -EINVAL;
85         dev = MINOR(inode->i_rdev);
86         if (dev != SNAP_PSDEV_MINOR)
87                 return -ENODEV;
88
89         MOD_DEC_USE_COUNT;
90
91         EXIT;
92         return 0;
93 }
94
95 /* XXX need ioctls here to do snap_delete and snap_restore, snap_backup */
96
97
98 /* declare character device */
99 static struct file_operations snapcontrol_fops = {
100         NULL,                  /* llseek */
101         NULL,                  /* read */
102         NULL,                  /* write */
103         NULL,                  /* presto_psdev_readdir */
104         NULL,                  /* poll */
105         snap_ioctl,            /* ioctl */
106         NULL,                  /* presto_psdev_mmap */
107         snap_psdev_open,       /* open */
108         NULL,
109         snap_psdev_release,    /* release */
110         NULL,                  /* fsync */
111         NULL,                  /* fasync */
112         NULL                   /* lock */
113 };
114
115
116
117 #define SNAPFS_MINOR 240
118
119 static struct miscdevice snapcontrol_dev = {
120         SNAPFS_MINOR,
121         "snapcontrol",
122         &snapcontrol_fops
123 };
124
125 int init_snap_psdev(void)
126 {
127         printk(KERN_INFO "SNAP psdev driver  v0.01, braam@mountainviewdata.com\n");
128         
129         misc_register( &snapcontrol_dev );
130
131         return 0;
132 }
133
134 void snap_cleanup_psdev(void)
135 {
136         ENTRY;
137         misc_deregister(&snapcontrol_dev);
138         EXIT;
139 }
140
141 #ifdef MODULE
142 MODULE_AUTHOR("Peter J. Braam <braam@cs.cmu.edu>");
143 MODULE_DESCRIPTION("Snapfs file system filters v0.01");
144
145 extern int init_snapfs(void);
146 extern int cleanup_snapfs(void);
147 extern int init_clonefs(void);
148 extern int init_snap_sysctl(void); 
149
150 int init_module(void)
151 {
152         int err;
153         if ( (err = init_snap_psdev()) ) {
154                 printk("Error initializing snap_psdev, %d\n", err);
155                 return -EINVAL;
156         }
157
158         if ( (err = init_snapfs()) ) {
159                 printk("Error initializing snapfs, %d\n", err);
160                 return -EINVAL;
161         }
162
163         if ( (err = init_snapfs_proc_sys()) ) {
164                 printk("Error initializing snapfs proc sys, %d\n", err);
165                 return -EINVAL;
166         }
167
168
169         return 0;
170 }
171
172 void cleanup_module(void)
173 {
174
175         cleanup_snapfs();
176         snap_cleanup_psdev();
177         
178 }
179 #endif
180