exofs: Multi-device mirror support
[safe/jmp/linux-2.6] / fs / exofs / common.h
1 /*
2  * common.h - Common definitions for both Kernel and user-mode utilities
3  *
4  * Copyright (C) 2005, 2006
5  * Avishay Traeger (avishay@gmail.com)
6  * Copyright (C) 2008, 2009
7  * Boaz Harrosh <bharrosh@panasas.com>
8  *
9  * Copyrights for code taken from ext2:
10  *     Copyright (C) 1992, 1993, 1994, 1995
11  *     Remy Card (card@masi.ibp.fr)
12  *     Laboratoire MASI - Institut Blaise Pascal
13  *     Universite Pierre et Marie Curie (Paris VI)
14  *     from
15  *     linux/fs/minix/inode.c
16  *     Copyright (C) 1991, 1992  Linus Torvalds
17  *
18  * This file is part of exofs.
19  *
20  * exofs is free software; you can redistribute it and/or modify
21  * it under the terms of the GNU General Public License as published by
22  * the Free Software Foundation.  Since it is based on ext2, and the only
23  * valid version of GPL for the Linux kernel is version 2, the only valid
24  * version of GPL for exofs is version 2.
25  *
26  * exofs is distributed in the hope that it will be useful,
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
29  * GNU General Public License for more details.
30  *
31  * You should have received a copy of the GNU General Public License
32  * along with exofs; if not, write to the Free Software
33  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
34  */
35
36 #ifndef __EXOFS_COM_H__
37 #define __EXOFS_COM_H__
38
39 #include <linux/types.h>
40
41 #include <scsi/osd_attributes.h>
42 #include <scsi/osd_initiator.h>
43 #include <scsi/osd_sec.h>
44
45 /****************************************************************************
46  * Object ID related defines
47  * NOTE: inode# = object ID - EXOFS_OBJ_OFF
48  ****************************************************************************/
49 #define EXOFS_MIN_PID   0x10000 /* Smallest partition ID */
50 #define EXOFS_OBJ_OFF   0x10000 /* offset for objects */
51 #define EXOFS_SUPER_ID  0x10000 /* object ID for on-disk superblock */
52 #define EXOFS_DEVTABLE_ID 0x10001 /* object ID for on-disk device table */
53 #define EXOFS_ROOT_ID   0x10002 /* object ID for root directory */
54
55 /* exofs Application specific page/attribute */
56 # define EXOFS_APAGE_FS_DATA    (OSD_APAGE_APP_DEFINED_FIRST + 3)
57 # define EXOFS_ATTR_INODE_DATA  1
58
59 /*
60  * The maximum number of files we can have is limited by the size of the
61  * inode number.  This is the largest object ID that the file system supports.
62  * Object IDs 0, 1, and 2 are always in use (see above defines).
63  */
64 enum {
65         EXOFS_MAX_INO_ID = (sizeof(ino_t) * 8 == 64) ? ULLONG_MAX :
66                                         (1ULL << (sizeof(ino_t) * 8ULL - 1ULL)),
67         EXOFS_MAX_ID     = (EXOFS_MAX_INO_ID - 1 - EXOFS_OBJ_OFF),
68 };
69
70 /****************************************************************************
71  * Misc.
72  ****************************************************************************/
73 #define EXOFS_BLKSHIFT  12
74 #define EXOFS_BLKSIZE   (1UL << EXOFS_BLKSHIFT)
75
76 /****************************************************************************
77  * superblock-related things
78  ****************************************************************************/
79 #define EXOFS_SUPER_MAGIC       0x5DF5
80
81 /*
82  * The file system control block - stored in object EXOFS_SUPER_ID's data.
83  * This is where the in-memory superblock is stored on disk.
84  */
85 enum {EXOFS_FSCB_VER = 1, EXOFS_DT_VER = 1};
86 struct exofs_fscb {
87         __le64  s_nextid;       /* Highest object ID used */
88         __le64  s_numfiles;     /* Number of files on fs */
89         __le32  s_version;      /* == EXOFS_FSCB_VER */
90         __le16  s_magic;        /* Magic signature */
91         __le16  s_newfs;        /* Non-zero if this is a new fs */
92
93         /* From here on it's a static part, only written by mkexofs */
94         __le64  s_dev_table_oid;   /* Resurved, not used */
95         __le64  s_dev_table_count; /* == 0 means no dev_table */
96 } __packed;
97
98 /*
99  * Describes the raid used in the FS. It is part of the device table.
100  * This here is taken from the pNFS-objects definition. In exofs we
101  * use one raid policy through-out the filesystem. (NOTE: the funny
102  * alignment at begining. We take care of it at exofs_device_table.
103  */
104 struct exofs_dt_data_map {
105         __le32  cb_num_comps;
106         __le64  cb_stripe_unit;
107         __le32  cb_group_width;
108         __le32  cb_group_depth;
109         __le32  cb_mirror_cnt;
110         __le32  cb_raid_algorithm;
111 } __packed;
112
113 /*
114  * This is an osd device information descriptor. It is a single entry in
115  * the exofs device table. It describes an osd target lun which
116  * contains data belonging to this FS. (Same partition_id on all devices)
117  */
118 struct exofs_dt_device_info {
119         __le32  systemid_len;
120         u8      systemid[OSD_SYSTEMID_LEN];
121         __le64  long_name_offset;       /* If !0 then offset-in-file */
122         __le32  osdname_len;            /* */
123         u8      osdname[44];            /* Embbeded, Ususally an asci uuid */
124 } __packed;
125
126 /*
127  * The EXOFS device table - stored in object EXOFS_DEVTABLE_ID's data.
128  * It contains the raid used for this multy-device FS and an array of
129  * participating devices.
130  */
131 struct exofs_device_table {
132         __le32                          dt_version;     /* == EXOFS_DT_VER */
133         struct exofs_dt_data_map        dt_data_map;    /* Raid policy to use */
134
135         /* Resurved space For future use. Total includeing this:
136          * (8 * sizeof(le64))
137          */
138         __le64                          __Resurved[4];
139
140         __le64                          dt_num_devices; /* Array size */
141         struct exofs_dt_device_info     dt_dev_table[]; /* Array of devices */
142 } __packed;
143
144 /****************************************************************************
145  * inode-related things
146  ****************************************************************************/
147 #define EXOFS_IDATA             5
148
149 /*
150  * The file control block - stored in an object's attributes.  This is where
151  * the in-memory inode is stored on disk.
152  */
153 struct exofs_fcb {
154         __le64  i_size;                 /* Size of the file */
155         __le16  i_mode;                 /* File mode */
156         __le16  i_links_count;          /* Links count */
157         __le32  i_uid;                  /* Owner Uid */
158         __le32  i_gid;                  /* Group Id */
159         __le32  i_atime;                /* Access time */
160         __le32  i_ctime;                /* Creation time */
161         __le32  i_mtime;                /* Modification time */
162         __le32  i_flags;                /* File flags (unused for now)*/
163         __le32  i_generation;           /* File version (for NFS) */
164         __le32  i_data[EXOFS_IDATA];    /* Short symlink names and device #s */
165 };
166
167 #define EXOFS_INO_ATTR_SIZE     sizeof(struct exofs_fcb)
168
169 /* This is the Attribute the fcb is stored in */
170 static const struct __weak osd_attr g_attr_inode_data = ATTR_DEF(
171         EXOFS_APAGE_FS_DATA,
172         EXOFS_ATTR_INODE_DATA,
173         EXOFS_INO_ATTR_SIZE);
174
175 /****************************************************************************
176  * dentry-related things
177  ****************************************************************************/
178 #define EXOFS_NAME_LEN  255
179
180 /*
181  * The on-disk directory entry
182  */
183 struct exofs_dir_entry {
184         __le64          inode_no;               /* inode number           */
185         __le16          rec_len;                /* directory entry length */
186         u8              name_len;               /* name length            */
187         u8              file_type;              /* umm...file type        */
188         char            name[EXOFS_NAME_LEN];   /* file name              */
189 };
190
191 enum {
192         EXOFS_FT_UNKNOWN,
193         EXOFS_FT_REG_FILE,
194         EXOFS_FT_DIR,
195         EXOFS_FT_CHRDEV,
196         EXOFS_FT_BLKDEV,
197         EXOFS_FT_FIFO,
198         EXOFS_FT_SOCK,
199         EXOFS_FT_SYMLINK,
200         EXOFS_FT_MAX
201 };
202
203 #define EXOFS_DIR_PAD                   4
204 #define EXOFS_DIR_ROUND                 (EXOFS_DIR_PAD - 1)
205 #define EXOFS_DIR_REC_LEN(name_len) \
206         (((name_len) + offsetof(struct exofs_dir_entry, name)  + \
207           EXOFS_DIR_ROUND) & ~EXOFS_DIR_ROUND)
208
209 #endif /*ifndef __EXOFS_COM_H__*/