Whamcloud - gitweb
New files:
[fs/lustre-release.git] / lustre / include / linux / obd_class.h
1 #ifndef __LINUX_CLASS_OBD_H
2 #define __LINUX_CLASS_OBD_H
3
4 #include <linux/fs.h>
5 #include <linux/ext2_fs.h>
6
7 #include <linux/obd.h>
8
9 #include <linux/obd_sim.h>
10 #include <linux/obd_snap.h>
11 /* #include <linux/obd_fc.h> */
12 #include <linux/obd_raid1.h>
13
14
15 #define OBD_PSDEV_MAJOR 120
16 #define MAX_OBD_DEVICES 2
17 #define MAX_MULTI 16
18
19 typedef unsigned long objid;
20 typedef struct inode obdattr;
21
22 extern struct obd_device obd_dev[MAX_OBD_DEVICES];
23
24
25
26 #define OBD_ATTACHED 0x1
27 #define OBD_SET_UP   0x2
28
29 /* corresponds to one of the obdx */
30 struct obd_device {
31         struct obd_type *obd_type;
32         int obd_minor;
33         int obd_flags;
34         int obd_refcnt; 
35         int obd_multi_count;
36         struct obd_device *obd_multi_dev[MAX_MULTI];
37         struct obd_conn_info obd_multi_conns[MAX_MULTI];
38         unsigned int obd_gen_last_id;
39         unsigned long obd_gen_prealloc_quota;
40         struct list_head obd_gen_clients;
41         union {
42                 struct sim_obd sim;
43                 struct raid1_obd raid1;
44                 struct snap_obd snap;
45                 /* struct fc_obd fc; */
46         } u;
47 };
48
49 struct obd_ops {
50         int (*o_attach)(struct obd_device *, int len, void *);
51         int (*o_format)(struct obd_device *, int len, void *);
52         int (*o_partition)(struct obd_device *, int len, void *);
53         int (*o_connect)(struct obd_device *, struct obd_conn_info *info);
54         int (*o_disconnect)(unsigned int conn_id);
55         int (*o_setup) (struct obd_device *dev, int len, void *data);
56         int (*o_cleanup)(struct obd_device *dev);
57         int (*o_setattr)(unsigned int conn_id, unsigned long id, struct inode *iattr);
58         int (*o_getattr)(unsigned int conn_id, unsigned long id, struct inode *iattr);
59         int (*o_statfs)(unsigned int conn_id, struct statfs *statfs);
60         int (*o_create)(int conn_id, int prealloc_ino, int *er);
61         int (*o_destroy)(unsigned int conn_id, unsigned long ino);
62         unsigned long (*o_read)(unsigned int conn_id, unsigned long ino, char *buf, unsigned long count, loff_t offset, int *err);
63         unsigned long (*o_read2)(unsigned int conn_id, unsigned long ino, char *buf, unsigned long count, loff_t offset, int *err);
64         unsigned long (*o_write)(unsigned int conn_id, unsigned long ino, char *buf, unsigned long count, loff_t offset, int *err);
65         int (*o_brw)(int rw, int conn, int objectid, struct page *page, int create);
66         long (*o_preallocate)(unsigned int conn_id, int req, long inodes[32], int *err);
67         int (*o_cleanup_device)(struct obd_device *);
68         int  (*o_get_info)(unsigned int conn_id, int keylen, void *key, int *vallen, void **val);
69         int  (*o_set_info)(unsigned int conn_id, int keylen, void *key, int vallen, void *val);
70 };
71
72 #define OBP(dev,op) dev->obd_type->typ_ops->o_ ## op
73
74 int obd_register_type(struct obd_ops *ops, char *nm);
75 int obd_unregister_type(char *nm);
76
77 struct obd_client {
78         struct list_head cli_chain;
79         struct obd_device *cli_obd;
80         unsigned int cli_id;
81         unsigned long cli_prealloc_quota;
82         struct list_head cli_prealloc_inodes;
83 };
84
85 struct obd_prealloc_inode {
86         struct list_head obd_prealloc_chain;
87         unsigned long inode;
88 };
89
90 /* generic operations shared by various OBD types */
91 int gen_connect (struct obd_device *obddev, 
92                      struct obd_conn_info * conninfo);
93 int gen_disconnect(unsigned int conn_id);
94 int gen_multi_setup(struct obd_device *obddev, int len, void *data);
95 int gen_multi_cleanup(struct obd_device *obddev);
96 int gen_multi_attach(struct obd_device *obddev, int len, void *data);
97 struct obd_client *gen_client(int cli_id);
98 int gen_multi_cleanup_device(struct obd_device *obddev);
99 int gen_cleanup(struct obd_device *obddev);
100
101
102
103 /*
104  * ioctl commands
105  */
106 struct oic_attach {
107         int  att_typelen;
108         void *att_type;
109         int  att_datalen;
110         void *att_data;
111 };
112
113 struct oic_prealloc_s {
114         unsigned long cli_id;
115         unsigned long alloc; /* user sets it to the number of inodes requesting
116                      * to be preallocated.  kernel sets it to the actual number
117                      * of succesfully preallocated inodes */
118         long inodes[32]; /* actual inode numbers */
119 };
120
121 struct oic_create_s {
122         unsigned int conn_id;
123         unsigned long prealloc;
124 };
125
126 struct oic_attr_s {
127         unsigned int conn_id;
128         unsigned long ino;
129         struct iattr iattr;
130 };
131 struct oic_rw_s {
132         unsigned int conn_id;
133         unsigned long inode;
134         char * buf;
135         unsigned long count;
136         loff_t offset;
137 };
138 struct oic_partition {
139         int partition;
140         unsigned int size;
141 };
142
143
144 #define OBD_IOC_CREATE                 _IOR ('f',  3, long)
145 #define OBD_IOC_SETUP_OBDDEV           _IOW ('f',  4, long)
146 #define OBD_IOC_CLEANUP                _IO  ('f',  5      )
147 #define OBD_IOC_DESTROY                _IOW ('f',  6, long)
148 #define OBD_IOC_PREALLOCATE            _IOWR('f',  7, long)
149 #define OBD_IOC_DEC_USE_COUNT          _IO  ('f',  8      )
150 #define OBD_IOC_SETATTR                _IOW ('f',  9, long)
151 #define OBD_IOC_GETATTR                _IOR ('f', 10, long)
152 #define OBD_IOC_READ                   _IOWR('f', 11, long)
153 #define OBD_IOC_WRITE                  _IOWR('f', 12, long)
154 #define OBD_IOC_CONNECT                _IOR ('f', 13, long)
155 #define OBD_IOC_DISCONNECT             _IOW ('f', 14, long)
156 #define OBD_IOC_STATFS                 _IOWR('f', 15, long)
157 #define OBD_IOC_SYNC                   _IOR ('f',  16, long)
158 #define OBD_IOC_READ2                  _IOWR('f', 17, long)
159 #define OBD_IOC_FORMAT                 _IOWR('f', 18, long)
160 #define OBD_IOC_PARTITION              _IOWR('f', 19, long)
161 #define OBD_IOC_ATTACH                 _IOWR('f', 20, long)
162
163 #define OBD_IOC_DEC_FS_USE_COUNT       _IO  ('f', 32      )
164
165
166 /* sysctl.c */
167 extern void obd_sysctl_init (void);
168 extern void obd_sysctl_clean (void);
169
170
171 #endif /* __LINUX_CLASS_OBD_H */