~ubuntu-branches/ubuntu/vivid/aufs/vivid

« back to all changes in this revision

Viewing changes to fs/aufs/super.h

  • Committer: Bazaar Package Importer
  • Author(s): Julian Andres Klode
  • Date: 2008-05-06 18:35:50 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20080506183550-0b6c974kkgc46oeh
Tags: 0+20080506-1
* New upstream release, supports Kernel 2.6.25 (Closes: #479717)
* Fix building with older Kernels (Closes: #475042)
* Update the patches 01, 04 and 07 to also patch fs/aufs25

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
/*
20
20
 * super_block operations
21
21
 *
22
 
 * $Id: super.h,v 1.75 2008/03/31 07:43:14 sfjro Exp $
 
22
 * $Id: super.h,v 1.77 2008/04/13 23:45:08 sfjro Exp $
23
23
 */
24
24
 
25
25
#ifndef __AUFS_SUPER_H__
38
38
#include <linux/aufs_type.h>
39
39
//#include "hinode.h"
40
40
#include "misc.h"
41
 
#include "opts.h"
 
41
//#include "opts.h"
42
42
#include "wkq.h"
43
43
 
44
 
typedef ssize_t (*readf_t)(struct file *, char __user *, size_t, loff_t *);
45
 
typedef ssize_t (*writef_t)(struct file *, const char __user *, size_t,
46
 
                            loff_t *);
 
44
typedef ssize_t (*au_readf_t)(struct file *, char __user *, size_t, loff_t *);
 
45
typedef ssize_t (*au_writef_t)(struct file *, const char __user *, size_t,
 
46
                               loff_t *);
47
47
 
48
48
struct au_wbr_copyup_operations {
49
49
        int (*copyup)(struct dentry *dentry);
79
79
        { (sbinfo)->au_si_status &= ~AuSi_##name; }
80
80
 
81
81
struct sysaufs_sbinfo;
82
 
struct aufs_branch;
83
 
struct aufs_sbinfo {
 
82
struct au_branch;
 
83
struct au_sbinfo {
84
84
        /* nowait tasks in the system-wide workqueue */
85
85
        struct au_nowait_tasks  si_nowait;
86
86
 
87
 
        struct aufs_rwsem       si_rwsem;
 
87
        struct au_rwsem         si_rwsem;
88
88
 
89
89
        /* branch management */
90
90
        au_gen_t                si_generation;
94
94
 
95
95
        aufs_bindex_t           si_bend;
96
96
        aufs_bindex_t           si_last_br_id;
97
 
        struct aufs_branch      **si_branch;
 
97
        struct au_branch        **si_branch;
98
98
 
99
99
        /* policy to select a writable branch */
 
100
        unsigned char           si_wbr_copyup;
 
101
        unsigned char           si_wbr_create;
100
102
        struct au_wbr_copyup_operations *si_wbr_copyup_ops;
101
103
        struct au_wbr_create_operations *si_wbr_create_ops;
102
104
 
108
110
 
109
111
        /* mount flags */
110
112
        /* include/asm-ia64/siginfo.h defines a macro named si_flags */
111
 
        struct au_opts_flags    au_si_flags;
 
113
        unsigned int            si_mntflags;
112
114
 
113
115
        /* external inode number (bitmap and translation table) */
114
 
        readf_t                 si_xread;
115
 
        writef_t                si_xwrite;
 
116
        au_readf_t              si_xread;
 
117
        au_writef_t             si_xwrite;
116
118
        struct file             *si_xib;
117
119
        struct mutex            si_xib_mtx; /* protect xib members */
118
120
        unsigned long           *si_xib_buf;
125
127
 
126
128
        /*
127
129
         * If the number of whiteouts are larger than si_dirwh, leave all of
128
 
         * them after rename_whtmp to reduce the cost of rmdir(2).
 
130
         * them after au_whtmp_ren to reduce the cost of rmdir(2).
129
131
         * future fsck.aufs or kernel thread will remove them later.
130
132
         * Otherwise, remove all whiteouts and the dir in rmdir(2).
131
133
         */
141
143
        struct list_head        si_plink;
142
144
 
143
145
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 18)
 
146
        struct vfsmount         *si_mnt;        /* no get/put */
 
147
#endif
 
148
 
 
149
        /* sysfs */
 
150
#ifdef CONFIG_AUFS_SYSAUFS
144
151
        /* super_blocks list is not exported */
145
152
        struct list_head        si_list;
146
 
        struct vfsmount         *si_mnt;        /* no get/put */
147
 
#endif
148
 
 
149
 
        /* sysfs */
150
153
        struct sysaufs_sbinfo   *si_sa;
 
154
#endif
151
155
 
152
156
#ifdef CONFIG_AUFS_ROBR
153
157
        /* locked vma list for mmap() */ // very dirty
157
161
};
158
162
 
159
163
/* ---------------------------------------------------------------------- */
160
 
/* mount flags */
161
 
#define AuFlag(sbinfo, name)            ({ (sbinfo)->au_si_flags.name; })
162
 
#define AuFlagSet(sbinfo, name, val)    { (sbinfo)->au_si_flags.name = (val); }
163
164
 
164
165
/* policy to select one among writable branches */
165
166
#define AuWbrCopyup(sbinfo, args... ) \
168
169
        (sbinfo)->si_wbr_create_ops->create(args)
169
170
 
170
171
/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */
171
 
#define AuLock_DW               1
172
 
#define AuLock_IR               (1 << 1)
173
 
#define AuLock_IW               (1 << 2)
174
 
#define AuLock_FLUSH            (1 << 3)
175
 
#define AuLock_DIR              (1 << 4)
 
172
#define AuLock_DW               1               /* write-lock dentry */
 
173
#define AuLock_IR               (1 << 1)        /* read-lock inode */
 
174
#define AuLock_IW               (1 << 2)        /* write-lock inode */
 
175
#define AuLock_FLUSH            (1 << 3)        /* wait for 'nowait' tasks */
 
176
#define AuLock_DIR              (1 << 4)        /* target is a dir */
176
177
#define au_ftest_lock(flags, name)      ((flags) & AuLock_##name)
177
178
#define au_fset_lock(flags, name)       { (flags) |= AuLock_##name; }
178
179
#define au_fclr_lock(flags, name)       { (flags) &= ~AuLock_##name; }
180
181
/* ---------------------------------------------------------------------- */
181
182
 
182
183
/* super.c */
183
 
struct seq_file;
184
 
int au_show_brs(struct seq_file *seq, struct super_block *sb);
185
184
extern struct file_system_type aufs_fs_type;
186
185
 
187
186
/* sbinfo.c */
188
 
struct aufs_sbinfo *stosi(struct super_block *sb);
189
 
aufs_bindex_t sbend(struct super_block *sb);
190
 
struct aufs_branch *stobr(struct super_block *sb, aufs_bindex_t bindex);
191
 
au_gen_t au_sigen(struct super_block *sb);
 
187
struct au_branch *au_sbr(struct super_block *sb, aufs_bindex_t bindex);
192
188
au_gen_t au_sigen_inc(struct super_block *sb);
193
 
int find_bindex(struct super_block *sb, struct aufs_branch *br);
 
189
int au_find_bindex(struct super_block *sb, struct au_branch *br);
194
190
 
195
191
void aufs_read_lock(struct dentry *dentry, int flags);
196
192
void aufs_read_unlock(struct dentry *dentry, int flags);
199
195
void aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int isdir);
200
196
void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2);
201
197
 
202
 
aufs_bindex_t new_br_id(struct super_block *sb);
 
198
aufs_bindex_t au_new_br_id(struct super_block *sb);
203
199
 
204
200
/* wbr_policy.c */
205
201
extern struct au_wbr_copyup_operations au_wbr_copyup_ops[];
209
205
 
210
206
/* ---------------------------------------------------------------------- */
211
207
 
 
208
static inline struct au_sbinfo *au_sbi(struct super_block *sb)
 
209
{
 
210
        return sb->s_fs_info;
 
211
}
 
212
 
212
213
static inline const char *au_sbtype(struct super_block *sb)
213
214
{
214
215
        return sb->s_type->name;
216
217
 
217
218
static inline int au_test_aufs(struct super_block *sb)
218
219
{
219
 
#ifdef AUFS_SUPER_MAGIC
220
220
        return (sb->s_magic == AUFS_SUPER_MAGIC);
 
221
}
 
222
 
 
223
static inline int au_test_nfs(struct super_block *sb)
 
224
{
 
225
#ifdef CONFIG_AUFS_BR_NFS
 
226
        return (sb->s_magic == NFS_SUPER_MAGIC);
221
227
#else
222
 
        return !strcmp(au_sbtype(sb), AUFS_FSTYPE);
 
228
        return 0;
223
229
#endif
224
230
}
225
231
 
226
232
static inline int au_test_fuse(struct super_block *sb)
227
233
{
228
 
        int ret = 0;
229
234
#ifdef CONFIG_AUFS_WORKAROUND_FUSE
230
235
#ifdef FUSE_SUPER_MAGIC
231
236
        BUILD_BUG_ON(FUSE_SUPER_MAGIC != 0x65735546);
232
 
        ret = (sb->s_magic == FUSE_SUPER_MAGIC);
 
237
        return (sb->s_magic == FUSE_SUPER_MAGIC);
233
238
#else
234
 
        ret = !strcmp(au_sbtype(sb), "fuse");
235
 
#endif
236
 
#endif
237
 
        return ret;
 
239
        return !strcmp(au_sbtype(sb), "fuse");
 
240
#endif
 
241
#endif
 
242
        return 0;
238
243
}
239
244
 
240
245
static inline int au_test_xfs(struct super_block *sb)
241
246
{
242
 
        int ret = 0;
243
 
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) \
244
 
        && (defined(CONFIG_XFS_FS) || defined(CONFIG_XFS_FS_MODULE))
 
247
#ifdef CONFIG_AUFS_BR_XFS
245
248
#ifdef XFS_SB_MAGIC
246
249
        BUILD_BUG_ON(XFS_SB_MAGIC != 0x58465342);
247
 
        ret = (sb->s_magic == XFS_SB_MAGIC);
248
 
#else
249
 
        ret = !strcmp(au_sbtype(sb), "xfs");
250
 
#endif
251
 
#endif
252
 
        return ret;
253
 
}
254
 
 
255
 
static inline int au_test_nfs(struct super_block *sb)
256
 
{
257
 
#if defined(CONFIG_NFS_FS) || defined(CONFIG_NFS_FS_MODULE)
258
 
        return (sb->s_magic == NFS_SUPER_MAGIC);
259
 
#else
 
250
        return (sb->s_magic == XFS_SB_MAGIC);
 
251
#else
 
252
        return !strcmp(au_sbtype(sb), "xfs");
 
253
#endif
 
254
#endif
260
255
        return 0;
261
 
#endif
262
256
}
263
257
 
264
258
static inline int au_test_tmpfs(struct super_block *sb)
265
259
{
266
 
        int ret = 0;
267
260
#ifdef CONFIG_TMPFS
268
261
#ifdef TMPFS_MAGIC
269
262
        BUILD_BUG_ON(TMPFS_MAGIC != 0x01021994);
270
 
        ret = (sb->s_magic == TMPFS_MAGIC);
 
263
        return (sb->s_magic == TMPFS_MAGIC);
271
264
#else
272
 
        ret = !strcmp(au_sbtype(sb), "tmpfs");
273
 
#endif
274
 
#endif
275
 
        return ret;
276
 
}
277
 
 
278
 
static inline int au_test_trunc_xino(struct super_block *sb)
279
 
{
280
 
        return au_test_tmpfs(sb);
281
 
}
282
 
 
283
 
/* temporary support for i#1 in cramfs */
284
 
static inline int au_test_unique_ino(struct dentry *h_dentry, ino_t h_ino)
285
 
{
286
 
#if defined(CONFIG_CRAMFS) || defined(CONFIG_CRAMFS_MODULE)
287
 
        if (unlikely(h_dentry->d_sb->s_magic == CRAMFS_MAGIC))
288
 
                return (h_ino != 1);
289
 
#endif
290
 
        return 1;
291
 
}
 
265
        return !strcmp(au_sbtype(sb), "tmpfs");
 
266
#endif
 
267
#endif
 
268
        return 0;
 
269
}
 
270
 
 
271
/* ---------------------------------------------------------------------- */
292
272
 
293
273
#ifdef CONFIG_AUFS_EXPORT
294
274
extern struct export_operations aufs_export_op;
313
293
        if (au_test_nfsd(current))
314
294
                lockdep_on();
315
295
}
316
 
 
317
296
#else
318
 
 
319
297
static inline int au_test_nfsd(struct task_struct *tsk)
320
298
{
321
299
        return 0;
328
306
 
329
307
#define au_nfsd_lockdep_off()   do {} while (0)
330
308
#define au_nfsd_lockdep_on()    do {} while (0)
331
 
 
332
309
#endif /* CONFIG_AUFS_EXPORT */
333
310
 
334
 
/* ---------------------------------------------------------------------- */
335
 
 
336
311
#ifdef CONFIG_AUFS_ROBR
337
312
static inline int au_test_nested(struct super_block *h_sb)
338
313
{
339
314
        return 0;
340
315
}
341
316
 
342
 
static inline void au_robr_lvma_init(struct aufs_sbinfo *sbinfo)
 
317
static inline void au_robr_lvma_init(struct au_sbinfo *sbinfo)
343
318
{
344
319
        spin_lock_init(&sbinfo->si_lvma_lock);
345
320
        INIT_LIST_HEAD(&sbinfo->si_lvma);
348
323
static inline int au_test_nested(struct super_block *h_sb)
349
324
{
350
325
        int err = 0;
351
 
        if (unlikely(au_test_aufs(h_sb)))
 
326
        if (unlikely(au_test_aufs(h_sb))) {
352
327
                err = -EINVAL;
353
 
        AuTraceErr(err);
 
328
                AuTraceErr(err);
 
329
        }
354
330
        return err;
355
331
}
356
332
 
357
 
static inline void au_robr_lvma_init(struct aufs_sbinfo *sbinfo)
 
333
static inline void au_robr_lvma_init(struct au_sbinfo *sbinfo)
358
334
{
359
335
        /* empty */
360
336
}
362
338
 
363
339
/* ---------------------------------------------------------------------- */
364
340
 
365
 
/* limited support before 2.6.18 */
366
 
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 18)
367
 
static inline void au_mntget(struct super_block *sb)
368
 
{
369
 
        mntget(stosi(sb)->si_mnt);
370
 
}
371
 
 
372
 
static inline void au_mntput(struct super_block *sb)
373
 
{
374
 
        mntput(stosi(sb)->si_mnt);
375
 
}
376
 
 
377
 
static inline void au_sbilist_del(struct aufs_sbinfo *sbinfo)
378
 
{
379
 
        list_del(&sbinfo->si_list);
380
 
}
381
 
#else
382
 
static inline void au_mntget(struct super_block *sb)
383
 
{
384
 
        /* empty */
385
 
}
386
 
 
387
 
static inline void au_mntput(struct super_block *sb)
388
 
{
389
 
        /* empty */
390
 
}
391
 
 
392
 
static inline void au_sbilist_del(struct aufs_sbinfo *sbinfo)
393
 
{
394
 
        /* empty */
395
 
}
396
 
#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 18) */
397
 
 
398
 
/* ---------------------------------------------------------------------- */
399
 
 
400
 
static inline unsigned int au_flag_test_shwh(struct super_block *sb)
401
 
{
402
 
#ifdef CONFIG_AUFS_SHWH
403
 
        return (AuFlag(stosi(sb), f_shwh));
404
 
#else
405
 
        return 0;
406
 
#endif
407
 
}
408
 
 
409
 
/* ---------------------------------------------------------------------- */
410
 
 
411
 
static inline unsigned int au_flag_test_udba_inotify(struct super_block *sb)
412
 
{
413
 
#ifdef CONFIG_AUFS_HINOTIFY
414
 
        return (AuFlag(stosi(sb), f_udba) == AuUdba_INOTIFY);
415
 
#else
416
 
        return 0;
417
 
#endif
418
 
}
419
 
 
420
 
#ifdef CONFIG_AUFS_DLGT
421
 
static inline int au_need_dlgt(struct super_block *sb)
422
 
{
423
 
        return (AuFlag(stosi(sb), f_dlgt) && !au_test_wkq(current));
424
 
}
425
 
 
426
 
static inline int au_need_dirperm1(struct super_block *sb)
427
 
{
428
 
        return (AuFlag(stosi(sb), f_dirperm1) && !au_test_wkq(current));
429
 
}
430
 
#else
431
 
static inline int au_need_dlgt(struct super_block *sb)
432
 
{
433
 
        return 0;
434
 
}
435
 
 
436
 
static inline int au_need_dirperm1(struct super_block *sb)
437
 
{
438
 
        return 0;
439
 
}
440
 
#endif
441
 
 
442
 
/* ---------------------------------------------------------------------- */
443
 
 
444
341
/* lock superblock. mainly for entry point functions */
445
342
/*
446
343
 * si_noflush_read_lock, si_noflush_write_lock,
447
344
 * si_read_unlock, si_write_unlock, si_downgrade_lock
448
345
 */
449
 
SimpleLockRwsemFuncs(si_noflush, struct super_block *sb, stosi(sb)->si_rwsem);
450
 
SimpleUnlockRwsemFuncs(si, struct super_block *sb, stosi(sb)->si_rwsem);
 
346
AuSimpleLockRwsemFuncs(si_noflush, struct super_block *sb,
 
347
                       au_sbi(sb)->si_rwsem);
 
348
AuSimpleUnlockRwsemFuncs(si, struct super_block *sb, au_sbi(sb)->si_rwsem);
451
349
 
452
350
static inline void si_read_lock(struct super_block *sb, int flags)
453
351
{
454
352
        if (au_ftest_lock(flags, FLUSH))
455
 
                au_nwt_flush(&stosi(sb)->si_nowait);
 
353
                au_nwt_flush(&au_sbi(sb)->si_nowait);
456
354
        si_noflush_read_lock(sb);
457
355
}
458
356
 
459
357
static inline void si_write_lock(struct super_block *sb)
460
358
{
461
 
        au_nwt_flush(&stosi(sb)->si_nowait);
 
359
        au_nwt_flush(&au_sbi(sb)->si_nowait);
462
360
        si_noflush_write_lock(sb);
463
361
}
464
362
 
465
363
static inline int si_read_trylock(struct super_block *sb, int flags)
466
364
{
467
365
        if (au_ftest_lock(flags, FLUSH))
468
 
                au_nwt_flush(&stosi(sb)->si_nowait);
 
366
                au_nwt_flush(&au_sbi(sb)->si_nowait);
469
367
        return si_noflush_read_trylock(sb);
470
368
}
471
369
 
472
370
static inline int si_write_trylock(struct super_block *sb, int flags)
473
371
{
474
372
        if (au_ftest_lock(flags, FLUSH))
475
 
                au_nwt_flush(&stosi(sb)->si_nowait);
 
373
                au_nwt_flush(&au_sbi(sb)->si_nowait);
476
374
        return si_noflush_write_trylock(sb);
477
375
}
478
376
 
479
377
/* to debug easier, do not make them inlined functions */
480
 
#define SiMustReadLock(sb)      RwMustReadLock(&stosi(sb)->si_rwsem)
481
 
#define SiMustWriteLock(sb)     RwMustWriteLock(&stosi(sb)->si_rwsem)
482
 
#define SiMustAnyLock(sb)       RwMustAnyLock(&stosi(sb)->si_rwsem)
 
378
#define SiMustReadLock(sb)      AuRwMustReadLock(&au_sbi(sb)->si_rwsem)
 
379
#define SiMustWriteLock(sb)     AuRwMustWriteLock(&au_sbi(sb)->si_rwsem)
 
380
#define SiMustAnyLock(sb)       AuRwMustAnyLock(&au_sbi(sb)->si_rwsem)
 
381
 
 
382
/* ---------------------------------------------------------------------- */
 
383
 
 
384
static inline aufs_bindex_t au_sbend(struct super_block *sb)
 
385
{
 
386
        SiMustAnyLock(sb);
 
387
        return au_sbi(sb)->si_bend;
 
388
}
 
389
 
 
390
static inline unsigned int au_mntflags(struct super_block *sb)
 
391
{
 
392
        SiMustAnyLock(sb);
 
393
        return au_sbi(sb)->si_mntflags;
 
394
}
 
395
 
 
396
static inline au_gen_t au_sigen(struct super_block *sb)
 
397
{
 
398
        SiMustAnyLock(sb);
 
399
        return au_sbi(sb)->si_generation;
 
400
}
 
401
 
 
402
/* ---------------------------------------------------------------------- */
 
403
 
 
404
/* limited support before 2.6.18 */
 
405
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 18)
 
406
static inline void au_mntget(struct super_block *sb)
 
407
{
 
408
        mntget(au_sbi(sb)->si_mnt);
 
409
}
 
410
 
 
411
static inline void au_mntput(struct super_block *sb)
 
412
{
 
413
        mntput(au_sbi(sb)->si_mnt);
 
414
}
 
415
#else
 
416
static inline void au_mntget(struct super_block *sb)
 
417
{
 
418
        /* empty */
 
419
}
 
420
 
 
421
static inline void au_mntput(struct super_block *sb)
 
422
{
 
423
        /* empty */
 
424
}
 
425
#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 18) */
483
426
 
484
427
#endif /* __KERNEL__ */
485
428
#endif /* __AUFS_SUPER_H__ */