diff options
Diffstat (limited to 'include/linux/backing-dev.h')
-rw-r--r-- | include/linux/backing-dev.h | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/include/linux/backing-dev.h b/include/linux/backing-dev.h new file mode 100644 index 000000000000..f7a1390d67f5 --- /dev/null +++ b/include/linux/backing-dev.h | |||
@@ -0,0 +1,104 @@ | |||
1 | /* | ||
2 | * include/linux/backing-dev.h | ||
3 | * | ||
4 | * low-level device information and state which is propagated up through | ||
5 | * to high-level code. | ||
6 | */ | ||
7 | |||
8 | #ifndef _LINUX_BACKING_DEV_H | ||
9 | #define _LINUX_BACKING_DEV_H | ||
10 | |||
11 | #include <asm/atomic.h> | ||
12 | |||
13 | /* | ||
14 | * Bits in backing_dev_info.state | ||
15 | */ | ||
16 | enum bdi_state { | ||
17 | BDI_pdflush, /* A pdflush thread is working this device */ | ||
18 | BDI_write_congested, /* The write queue is getting full */ | ||
19 | BDI_read_congested, /* The read queue is getting full */ | ||
20 | BDI_unused, /* Available bits start here */ | ||
21 | }; | ||
22 | |||
23 | typedef int (congested_fn)(void *, int); | ||
24 | |||
25 | struct backing_dev_info { | ||
26 | unsigned long ra_pages; /* max readahead in PAGE_CACHE_SIZE units */ | ||
27 | unsigned long state; /* Always use atomic bitops on this */ | ||
28 | unsigned int capabilities; /* Device capabilities */ | ||
29 | congested_fn *congested_fn; /* Function pointer if device is md/dm */ | ||
30 | void *congested_data; /* Pointer to aux data for congested func */ | ||
31 | void (*unplug_io_fn)(struct backing_dev_info *, struct page *); | ||
32 | void *unplug_io_data; | ||
33 | }; | ||
34 | |||
35 | |||
36 | /* | ||
37 | * Flags in backing_dev_info::capability | ||
38 | * - The first two flags control whether dirty pages will contribute to the | ||
39 | * VM's accounting and whether writepages() should be called for dirty pages | ||
40 | * (something that would not, for example, be appropriate for ramfs) | ||
41 | * - These flags let !MMU mmap() govern direct device mapping vs immediate | ||
42 | * copying more easily for MAP_PRIVATE, especially for ROM filesystems | ||
43 | */ | ||
44 | #define BDI_CAP_NO_ACCT_DIRTY 0x00000001 /* Dirty pages shouldn't contribute to accounting */ | ||
45 | #define BDI_CAP_NO_WRITEBACK 0x00000002 /* Don't write pages back */ | ||
46 | #define BDI_CAP_MAP_COPY 0x00000004 /* Copy can be mapped (MAP_PRIVATE) */ | ||
47 | #define BDI_CAP_MAP_DIRECT 0x00000008 /* Can be mapped directly (MAP_SHARED) */ | ||
48 | #define BDI_CAP_READ_MAP 0x00000010 /* Can be mapped for reading */ | ||
49 | #define BDI_CAP_WRITE_MAP 0x00000020 /* Can be mapped for writing */ | ||
50 | #define BDI_CAP_EXEC_MAP 0x00000040 /* Can be mapped for execution */ | ||
51 | #define BDI_CAP_VMFLAGS \ | ||
52 | (BDI_CAP_READ_MAP | BDI_CAP_WRITE_MAP | BDI_CAP_EXEC_MAP) | ||
53 | |||
54 | #if defined(VM_MAYREAD) && \ | ||
55 | (BDI_CAP_READ_MAP != VM_MAYREAD || \ | ||
56 | BDI_CAP_WRITE_MAP != VM_MAYWRITE || \ | ||
57 | BDI_CAP_EXEC_MAP != VM_MAYEXEC) | ||
58 | #error please change backing_dev_info::capabilities flags | ||
59 | #endif | ||
60 | |||
61 | extern struct backing_dev_info default_backing_dev_info; | ||
62 | void default_unplug_io_fn(struct backing_dev_info *bdi, struct page *page); | ||
63 | |||
64 | int writeback_acquire(struct backing_dev_info *bdi); | ||
65 | int writeback_in_progress(struct backing_dev_info *bdi); | ||
66 | void writeback_release(struct backing_dev_info *bdi); | ||
67 | |||
68 | static inline int bdi_congested(struct backing_dev_info *bdi, int bdi_bits) | ||
69 | { | ||
70 | if (bdi->congested_fn) | ||
71 | return bdi->congested_fn(bdi->congested_data, bdi_bits); | ||
72 | return (bdi->state & bdi_bits); | ||
73 | } | ||
74 | |||
75 | static inline int bdi_read_congested(struct backing_dev_info *bdi) | ||
76 | { | ||
77 | return bdi_congested(bdi, 1 << BDI_read_congested); | ||
78 | } | ||
79 | |||
80 | static inline int bdi_write_congested(struct backing_dev_info *bdi) | ||
81 | { | ||
82 | return bdi_congested(bdi, 1 << BDI_write_congested); | ||
83 | } | ||
84 | |||
85 | static inline int bdi_rw_congested(struct backing_dev_info *bdi) | ||
86 | { | ||
87 | return bdi_congested(bdi, (1 << BDI_read_congested)| | ||
88 | (1 << BDI_write_congested)); | ||
89 | } | ||
90 | |||
91 | #define bdi_cap_writeback_dirty(bdi) \ | ||
92 | (!((bdi)->capabilities & BDI_CAP_NO_WRITEBACK)) | ||
93 | |||
94 | #define bdi_cap_account_dirty(bdi) \ | ||
95 | (!((bdi)->capabilities & BDI_CAP_NO_ACCT_DIRTY)) | ||
96 | |||
97 | #define mapping_cap_writeback_dirty(mapping) \ | ||
98 | bdi_cap_writeback_dirty((mapping)->backing_dev_info) | ||
99 | |||
100 | #define mapping_cap_account_dirty(mapping) \ | ||
101 | bdi_cap_account_dirty((mapping)->backing_dev_info) | ||
102 | |||
103 | |||
104 | #endif /* _LINUX_BACKING_DEV_H */ | ||