Whamcloud - gitweb
Changes for file creation and small fixes.
[fs/lustre-release.git] / lustre / include / linux / lustre_light.h
1 /* object based disk file system
2  * 
3  * This code is issued under the GNU General Public License.
4  * See the file COPYING in this distribution
5  * 
6  * Copyright (C), 1999, Stelias Computing Inc
7  *
8  *
9  */
10
11
12 #ifndef _LL_H
13 #define _LL_H
14 #include <linux/obd_class.h>
15 #include <linux/obdo.h>
16 #include <linux/list.h>
17
18 #define LL_SUPER_MAGIC 0x0BD00BD0;
19
20 struct ll_inode_info {
21         int              lli_flags;
22         __u64            lli_objid; 
23         char             lli_inline[OBD_INLINESZ];
24 };
25
26 struct ll_sb_info {
27         struct list_head         ll_list;      /* list of supers */
28         struct obd_conn          ll_conn;
29         struct super_block      *ll_super;
30         //        struct obd_device       *ll_obd;
31         //struct obd_ops          *ll_ops;
32         ino_t                    ll_rootino;   /* number of root inode */
33         int                      ll_minor;     /* minor of /dev/obdX */
34         struct list_head         ll_inodes;    /* list of dirty inodes */
35         unsigned long            ll_cache_count;
36         struct semaphore         ll_list_mutex;
37 };
38
39
40 static inline struct ll_inode_info *ll_i2info(struct inode *inode)
41 {
42         return (struct ll_inode_info *)&(inode->u.generic_ip);
43 }
44
45 static inline int ll_has_inline(struct inode *inode)
46 {
47         return (ll_i2info(inode)->lli_flags & OBD_FL_INLINEDATA);
48 }
49
50 static void inline ll_from_inode(struct obdo *oa, struct inode *inode)
51 {
52         struct ll_inode_info *oinfo = ll_i2info(inode);
53
54         CDEBUG(D_INFO, "src inode %ld, dst obdo %ld valid 0x%08x\n",
55                inode->i_ino, (long)oa->o_id, oa->o_valid);
56         obdo_from_inode(oa, inode);
57         if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) {
58                 CDEBUG(D_INODE, "copying device %x from inode to obdo\n",
59                        inode->i_rdev);
60                 *((obd_rdev *)oa->o_inline) = kdev_t_to_nr(inode->i_rdev);
61                 oa->o_obdflags |= OBD_FL_INLINEDATA;
62                 oa->o_valid |= OBD_MD_FLINLINE;
63         } else if (ll_has_inline(inode)) {
64                 CDEBUG(D_INODE, "copying inline data from inode to obdo\n");
65                 memcpy(oa->o_inline, oinfo->lli_inline, OBD_INLINESZ);
66                 oa->o_obdflags |= OBD_FL_INLINEDATA;
67                 oa->o_valid |= OBD_MD_FLINLINE;
68         }
69 } /* ll_from_inode */
70
71
72
73
74
75
76 /* super.c */ 
77 struct ll_pgrq {
78         struct list_head         rq_plist;      /* linked list of req's */
79         unsigned long            rq_jiffies;
80         struct page             *rq_page;       /* page to be written */
81 };
82
83 extern struct list_head ll_super_list;       /* list of all LL superblocks */
84
85
86
87 /* dir.c */
88 #define EXT2_DIR_PAD                    4
89 #define EXT2_DIR_ROUND                  (EXT2_DIR_PAD - 1)
90 #define EXT2_DIR_REC_LEN(name_len)      (((name_len) + 8 + EXT2_DIR_ROUND) & \
91                                          ~EXT2_DIR_ROUND)
92 #define EXT2_NAME_LEN 255
93
94 int ll_check_dir_entry (const char * function, struct inode * dir,
95                           struct ext2_dir_entry_2 * de, struct page * page,
96                           unsigned long offset);
97 extern struct file_operations ll_dir_operations;
98 extern struct inode_operations ll_dir_inode_operations;
99
100 /* file.c */
101 extern struct file_operations ll_file_operations;
102 extern struct inode_operations ll_file_inode_operations;
103
104 /* flush.c */
105 void ll_dequeue_pages(struct inode *inode);
106 int ll_flushd_init(void);
107 int ll_flushd_cleanup(void);
108 int ll_flush_reqs(struct list_head *inode_list, unsigned long check_time);
109 int ll_flush_dirty_pages(unsigned long check_time);
110
111 /* namei.c */
112 /*
113  * Structure of the super block
114  */
115
116
117 #define EXT2_SB(sb)     (&((sb)->u.ext2_sb))
118 /*
119  * Maximal count of links to a file
120  */
121 #define EXT2_LINK_MAX           32000
122 /*
123  * Ext2 directory file types.  Only the low 3 bits are used.  The
124  * other bits are reserved for now.
125  */
126 #define EXT2_FT_UNKNOWN         0
127 #define EXT2_FT_REG_FILE        1
128 #define EXT2_FT_DIR             2
129 #define EXT2_FT_CHRDEV          3
130 #define EXT2_FT_BLKDEV          4
131 #define EXT2_FT_FIFO            5
132 #define EXT2_FT_SOCK            6
133 #define EXT2_FT_SYMLINK         7
134
135 #define EXT2_FT_MAX             8
136
137 #define EXT2_BTREE_FL                   0x00001000 /* btree format dir */
138 #define EXT2_RESERVED_FL                0x80000000 /* reserved for ext2 lib */
139 #define EXT2_FEATURE_INCOMPAT_FILETYPE          0x0002
140 #define EXT2_HAS_COMPAT_FEATURE(sb,mask)                        \
141         ( EXT2_SB(sb)->s_es->s_feature_compat & cpu_to_le32(mask) )
142 #define EXT2_HAS_INCOMPAT_FEATURE(sb,mask)                      \
143         ( EXT2_SB(sb)->s_es->s_feature_incompat & cpu_to_le32(mask) )
144
145 /* rw.c */
146 int ll_do_writepage(struct page *, int sync);
147 int ll_init_pgrqcache(void);
148 void ll_cleanup_pgrqcache(void);
149 inline void ll_pgrq_del(struct ll_pgrq *pgrq);
150 int ll_readpage(struct file *file, struct page *page);
151 int ll_prepare_write(struct file *file, struct page *page, unsigned from, unsigned to);
152 int ll_commit_write(struct file *file, struct page *page, unsigned from, unsigned to);
153 int ll_writepage(struct page *page);
154 struct page *ll_getpage(struct inode *inode, unsigned long offset,
155                            int create, int locked);
156 int ll_write_one_page(struct file *file, struct page *page,
157                          unsigned long offset, unsigned long bytes,
158                          const char * buf);
159 int ll_do_vec_wr(struct inode **inodes, obd_count num_io, obd_count num_oa,
160                     struct obdo **obdos, obd_count *oa_bufs,
161                     struct page **pages, char **bufs, obd_size *counts,
162                     obd_off *offsets, obd_flag *flags);
163 void ll_truncate(struct inode *inode);
164
165 /* super.c */
166 extern long ll_cache_count;
167 extern long ll_mutex_start;
168
169 /* symlink.c */
170 extern struct inode_operations ll_fast_symlink_inode_operations;
171 extern struct inode_operations ll_symlink_inode_operations;
172
173 /* sysctl.c */
174 void ll_sysctl_init(void);
175 void ll_sysctl_clean(void);
176
177 static inline struct ll_sb_info *ll_i2sbi(struct inode *inode)
178 {
179         return (struct ll_sb_info *) &(inode->i_sb->u.generic_sbp);
180 }
181
182
183 static inline struct list_head *ll_slist(struct inode *inode) 
184 {
185         struct ll_sb_info *sbi = ll_i2sbi(inode);
186
187         return &sbi->ll_inodes;
188 }
189
190 static void inline ll_set_size (struct inode *inode, obd_size size)
191 {  
192        inode->i_size = size;
193        inode->i_blocks = (inode->i_size + inode->i_sb->s_blocksize - 1) >>
194                inode->i_sb->s_blocksize_bits;
195 } /* ll_set_size */
196
197
198
199 #define obd_down(mutex) {                                               \
200         /* CDEBUG(D_INFO, "get lock\n"); */                             \
201         ll_mutex_start = jiffies;                                    \
202         down(mutex);                                                    \
203         if (jiffies - ll_mutex_start)                                \
204                 CDEBUG(D_CACHE, "waited on mutex %ld jiffies\n",        \
205                        jiffies - ll_mutex_start);                    \
206 }
207
208 #define obd_up(mutex) {                                                 \
209         up(mutex);                                                      \
210         if (jiffies - ll_mutex_start > 1)                            \
211                 CDEBUG(D_CACHE, "held mutex for %ld jiffies\n",         \
212                        jiffies - ll_mutex_start);                    \
213         /* CDEBUG(D_INFO, "free lock\n"); */                            \
214 }
215
216 /* We track if a page has been added to the OBD page cache by stting a
217  * flag on the page.  We have chosen a bit that will hopefully not be
218  * used for a while.
219  */
220 #define PG_obdcache 29
221 #define OBDAddCachePage(page)   test_and_set_bit(PG_obdcache, &(page)->flags)
222 #define OBDClearCachePage(page) clear_bit(PG_obdcache, &(page)->flags)
223
224 #endif
225