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.
9 #include "../../inode.h"
10 #include "../plugin.h"
12 static int should_deflate_none(struct inode
* inode
, cloff_t index
)
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
));
28 static int discard_hook_lattd(struct inode
*inode
, cloff_t index
)
30 struct cryptcompress_info
* info
= cryptcompress_inode_data(inode
);
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);
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
);
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
) ||
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
] = {
78 .type_id
= REISER4_COMPRESSION_MODE_PLUGIN_TYPE
,
79 .id
= NONE_COMPRESSION_MODE_ID
,
82 .desc
= "Compress nothing",
83 .linkage
= {NULL
, NULL
}
85 .should_deflate
= should_deflate_none
,
89 /* Check-on-dynamic-lattice adaptive compression mode */
90 [LATTD_COMPRESSION_MODE_ID
] = {
92 .type_id
= REISER4_COMPRESSION_MODE_PLUGIN_TYPE
,
93 .id
= LATTD_COMPRESSION_MODE_ID
,
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
] = {
108 .type_id
= REISER4_COMPRESSION_MODE_PLUGIN_TYPE
,
109 .id
= ULTIM_COMPRESSION_MODE_ID
,
112 .desc
= "Check ultimately",
113 .linkage
= {NULL
, NULL
}
115 .should_deflate
= should_deflate_common
,
117 .discard_hook
= discard_hook_ultim
119 /* Force-to-compress-everything compression mode */
120 [FORCE_COMPRESSION_MODE_ID
] = {
122 .type_id
= REISER4_COMPRESSION_MODE_PLUGIN_TYPE
,
123 .id
= FORCE_COMPRESSION_MODE_ID
,
126 .desc
= "Force to compress everything",
127 .linkage
= {NULL
, NULL
}
129 .should_deflate
= 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
138 [CONVX_COMPRESSION_MODE_ID
] = {
140 .type_id
= REISER4_COMPRESSION_MODE_PLUGIN_TYPE
,
141 .id
= CONVX_COMPRESSION_MODE_ID
,
144 .desc
= "Convert to extent",
145 .linkage
= {NULL
, NULL
}
147 .should_deflate
= should_deflate_common
,
155 c-indentation-style: "K&R"