Whamcloud - gitweb
ff8fc9a94c706584dc0339ad9971df54cc4637c0
[fs/lustre-release.git] / lustre / include / linux / obd_snap_support.h
1 #ifndef __OBD_SNAP_SUPP_H
2 #define __OBD_SNAP_SUPP_H
3
4 /* What we use to point to IDs in the obdmd data for snapshots.  If we use
5  * obd_id (8 bytes) instead of ino_t (4 bytes), we halve the number of
6  * available snapshot slots (14 in 56 bytes vs. 7 in 56 bytes until we
7  * increase the size of OBD_OBDMDSZ).
8  */
9 typedef ino_t   snap_id;
10
11 /* maximum number of snapshot tables we maintain in the kernel */
12 #define SNAP_MAX_TABLES 8
13
14 /* maximum number of snapshots per device 
15    must fit in "o_obdmd" area of struct obdo */
16 #define SNAP_MAX ((OBD_OBDMDSZ - sizeof(uint32_t))/sizeof(snap_id))
17
18 struct snap_md {
19         uint32_t m_magic;
20         snap_id  m_ids[SNAP_MAX];       /* id of snaps; slot 0 has current id */
21 };
22
23
24 /* if time is 0 this designates the "current" snapshot, i.e.
25    the head of the tree 
26 */
27 struct snap {
28         time_t time;
29         int index;
30 };
31
32 /* snap ioctl data for attach: current always in first slot of this array */
33 struct snap_obd_data {
34         int          snap_dev;  /* which device contains the data */
35         unsigned int snap_index;/* which snapshot is ours */
36         unsigned int snap_table;/* which table do we use */
37 };
38
39
40 /* snap ioctl data for table fiddling */
41 struct snap_table_data {
42         int             tblcmd_no;      /* which table */
43         unsigned int    tblcmd_count;   /* how many snaps */
44         struct snap     tblcmd_snaps[SNAP_MAX]; /* sorted times! */
45 };
46
47
48 struct snap_table {
49         spinlock_t          tbl_lock;
50         unsigned int tbl_count; /* how many snapshots exist in this table*/
51         int tbl_used;  /* bitmap of snaps in use by a device */
52         time_t tbl_times[SNAP_MAX];
53         int tbl_index[SNAP_MAX];
54 };
55
56 struct snap_iterdata {
57         struct obd_conn *conn;
58         struct obd_conn *ch_conn;
59         int index;
60         int previndex;
61         int currentindex;
62         int prevslot;
63         time_t prevtime;
64 };
65
66 inline struct obd_conn *child_conn(struct obd_conn *conn);
67 int snap_deleteobj(obd_id id, obd_gr group, void *data);
68 int snap_restoreobj(obd_id id, obd_gr group, void *data);
69 int snap_printobj(obd_id id, obd_gr group, void *data);
70 int snap_iocontrol(int cmd, struct obd_conn *conn, int len, void *karg, void *uarg);
71
72 /* In the future, this function may have to deal with offsets into the obdmd.
73  * Currently, we assume we have the whole obdmd struct.
74  */
75 static __inline__ struct snap_md *snap_obdmd(struct obdo *oa)
76 {
77         return ((struct snap_md *)(&oa->o_obdmd));
78 }
79 #endif