revert-mm-fix-blkdev-size-calculation-in-generic_write_checks
[linux-2.6/linux-trees-mm.git] / fs / reiser4 / plugin / compress / compress_mode.c
blob5e318caf995cf4f50028f2287cc6cf69e6e7338f
1 /* Copyright 2001, 2002, 2003 by Hans Reiser, licensing governed by reiser4/README */
2 /* This file contains Reiser4 compression mode plugins.
4 Compression mode plugin is a set of handlers called by compressor
5 at flush time and represent some heuristics including the ones
6 which are to avoid compression of incompressible data, see
7 http://www.namesys.com/cryptcompress_design.html for more details.
8 */
9 #include "../../inode.h"
10 #include "../plugin.h"
12 static int should_deflate_none(struct inode * inode, cloff_t index)
14 return 0;
17 static int should_deflate_common(struct inode * inode, cloff_t index)
19 return compression_is_on(cryptcompress_inode_data(inode));
22 static int discard_hook_ultim(struct inode *inode, cloff_t index)
24 turn_off_compression(cryptcompress_inode_data(inode));
25 return 0;
28 static int discard_hook_lattd(struct inode *inode, cloff_t index)
30 struct cryptcompress_info * info = cryptcompress_inode_data(inode);
32 assert("edward-1462",
33 get_lattice_factor(info) >= MIN_LATTICE_FACTOR &&
34 get_lattice_factor(info) <= MAX_LATTICE_FACTOR);
36 turn_off_compression(info);
37 if (get_lattice_factor(info) < MAX_LATTICE_FACTOR)
38 set_lattice_factor(info, get_lattice_factor(info) << 1);
39 return 0;
42 static int accept_hook_lattd(struct inode *inode, cloff_t index)
44 turn_on_compression(cryptcompress_inode_data(inode));
45 set_lattice_factor(cryptcompress_inode_data(inode), MIN_LATTICE_FACTOR);
46 return 0;
49 /* Check on dynamic lattice, the adaptive compression modes which
50 defines the following behavior:
52 Compression is on: try to compress everything and turn
53 it off, whenever cluster is incompressible.
55 Compression is off: try to compress clusters of indexes
56 k * FACTOR (k = 0, 1, 2, ...) and turn it on, if some of
57 them is compressible. If incompressible, then increase FACTOR */
59 /* check if @index belongs to one-dimensional lattice
60 of sparce factor @factor */
61 static int is_on_lattice(cloff_t index, int factor)
63 return (factor ? index % factor == 0: index == 0);
66 static int should_deflate_lattd(struct inode * inode, cloff_t index)
68 return should_deflate_common(inode, index) ||
69 is_on_lattice(index,
70 get_lattice_factor
71 (cryptcompress_inode_data(inode)));
74 /* compression mode_plugins */
75 compression_mode_plugin compression_mode_plugins[LAST_COMPRESSION_MODE_ID] = {
76 [NONE_COMPRESSION_MODE_ID] = {
77 .h = {
78 .type_id = REISER4_COMPRESSION_MODE_PLUGIN_TYPE,
79 .id = NONE_COMPRESSION_MODE_ID,
80 .pops = NULL,
81 .label = "none",
82 .desc = "Compress nothing",
83 .linkage = {NULL, NULL}
85 .should_deflate = should_deflate_none,
86 .accept_hook = NULL,
87 .discard_hook = NULL
89 /* Check-on-dynamic-lattice adaptive compression mode */
90 [LATTD_COMPRESSION_MODE_ID] = {
91 .h = {
92 .type_id = REISER4_COMPRESSION_MODE_PLUGIN_TYPE,
93 .id = LATTD_COMPRESSION_MODE_ID,
94 .pops = NULL,
95 .label = "lattd",
96 .desc = "Check on dynamic lattice",
97 .linkage = {NULL, NULL}
99 .should_deflate = should_deflate_lattd,
100 .accept_hook = accept_hook_lattd,
101 .discard_hook = discard_hook_lattd
103 /* Check-ultimately compression mode:
104 Turn off compression forever as soon as we meet
105 incompressible data */
106 [ULTIM_COMPRESSION_MODE_ID] = {
107 .h = {
108 .type_id = REISER4_COMPRESSION_MODE_PLUGIN_TYPE,
109 .id = ULTIM_COMPRESSION_MODE_ID,
110 .pops = NULL,
111 .label = "ultim",
112 .desc = "Check ultimately",
113 .linkage = {NULL, NULL}
115 .should_deflate = should_deflate_common,
116 .accept_hook = NULL,
117 .discard_hook = discard_hook_ultim
119 /* Force-to-compress-everything compression mode */
120 [FORCE_COMPRESSION_MODE_ID] = {
121 .h = {
122 .type_id = REISER4_COMPRESSION_MODE_PLUGIN_TYPE,
123 .id = FORCE_COMPRESSION_MODE_ID,
124 .pops = NULL,
125 .label = "force",
126 .desc = "Force to compress everything",
127 .linkage = {NULL, NULL}
129 .should_deflate = NULL,
130 .accept_hook = NULL,
131 .discard_hook = NULL
133 /* Convert-to-extent compression mode.
134 In this mode items will be converted to extents and management
135 will be passed to (classic) unix file plugin as soon as ->write()
136 detects that the first complete logical cluster (of index #0) is
137 incompressible. */
138 [CONVX_COMPRESSION_MODE_ID] = {
139 .h = {
140 .type_id = REISER4_COMPRESSION_MODE_PLUGIN_TYPE,
141 .id = CONVX_COMPRESSION_MODE_ID,
142 .pops = NULL,
143 .label = "conv",
144 .desc = "Convert to extent",
145 .linkage = {NULL, NULL}
147 .should_deflate = should_deflate_common,
148 .accept_hook = NULL,
149 .discard_hook = NULL
154 Local variables:
155 c-indentation-style: "K&R"
156 mode-name: "LC"
157 c-basic-offset: 8
158 tab-width: 8
159 fill-column: 120
160 scroll-step: 1
161 End: