Skip to content

Commit 749f071

Browse files
committed
Add configure --disable-tdb which disables e2fsck's scratch_files feature
The scratch_files feature is not really needed except on 32-bit platforms, since tdb's performance is pretty awful given how we are using it. Maybe SQLite would be faster, but for 64-bit platforms, enabling swap works fairly well, especially using the rbtree for the bitmap abstraction. We leave tdb for Android since it's unlikely that someone will be trying to connect petabyte+ sized file systems to a mobile handset. Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent a701823 commit 749f071

13 files changed

+198
-90
lines changed

configure

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,8 @@ SET_MAKE
731731
VERSION
732732
PACKAGE
733733
GETTEXT_PACKAGE
734+
TDB_MAN_COMMENT
735+
TDB_CMT
734736
UUIDD_CMT
735737
E2INITRD_MAN
736738
E2INITRD_PROG
@@ -877,6 +879,7 @@ enable_e2initrd_helper
877879
enable_tls
878880
enable_uuidd
879881
enable_mmp
882+
enable_tdb
880883
enable_bmap_stats
881884
enable_bmap_stats_ops
882885
enable_nls
@@ -1550,6 +1553,7 @@ Optional Features:
15501553
--disable-tls disable use of thread local support
15511554
--disable-uuidd disable building the uuid daemon
15521555
--disable-mmp disable support mmp, Multi Mount Protection
1556+
--disable-tdb disable tdb support
15531557
--disable-bmap-stats disable collection of bitmap stats.
15541558
--enable-bmap-stats-ops enable collection of additional bitmap stats
15551559
--disable-nls do not use Native Language Support
@@ -5940,6 +5944,36 @@ $as_echo "#define CONFIG_MMP 1" >>confdefs.h
59405944
fi
59415945

59425946

5947+
# Check whether --enable-tdb was given.
5948+
if test "${enable_tdb+set}" = set; then :
5949+
enableval=$enable_tdb; if test "$enableval" = "no"
5950+
then
5951+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Disabling tdb support" >&5
5952+
$as_echo "Disabling tdb support" >&6; }
5953+
TDB_CMT="#"
5954+
TDB_MAN_COMMENT='.\"'
5955+
else
5956+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Enabling tdb support" >&5
5957+
$as_echo "Enabling tdb support" >&6; }
5958+
$as_echo "#define CONFIG_TDB 1" >>confdefs.h
5959+
5960+
TDB_CMT=""
5961+
TDB_MAN_COMMENT=""
5962+
fi
5963+
5964+
else
5965+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: Enabling mmp support by default" >&5
5966+
$as_echo "Enabling mmp support by default" >&6; }
5967+
$as_echo "#define CONFIG_TDB 1" >>confdefs.h
5968+
5969+
TDB_CMT=""
5970+
TDB_MAN_COMMENT=""
5971+
5972+
fi
5973+
5974+
5975+
5976+
59435977
# Check whether --enable-bmap-stats was given.
59445978
if test "${enable_bmap_stats+set}" = set; then :
59455979
enableval=$enable_bmap_stats; if test "$enableval" = "no"

configure.ac

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,31 @@ AC_MSG_RESULT([Enabling mmp support by default])
777777
AC_DEFINE(CONFIG_MMP, 1)
778778
)
779779
dnl
780+
dnl handle --disable-tdb
781+
dnl
782+
AH_TEMPLATE([CONFIG_TDB], [Define to 1 to enable tdb support])
783+
AC_ARG_ENABLE([tdb],
784+
[ --disable-tdb disable tdb support],
785+
if test "$enableval" = "no"
786+
then
787+
AC_MSG_RESULT([Disabling tdb support])
788+
TDB_CMT="#"
789+
TDB_MAN_COMMENT='.\"'
790+
else
791+
AC_MSG_RESULT([Enabling tdb support])
792+
AC_DEFINE(CONFIG_TDB, 1)
793+
TDB_CMT=""
794+
TDB_MAN_COMMENT=""
795+
fi
796+
,
797+
AC_MSG_RESULT([Enabling mmp support by default])
798+
AC_DEFINE(CONFIG_TDB, 1)
799+
TDB_CMT=""
800+
TDB_MAN_COMMENT=""
801+
)
802+
AC_SUBST(TDB_CMT)
803+
AC_SUBST(TDB_MAN_COMMENT)
804+
dnl
780805
dnl handle --disable-bmap-stats
781806
dnl
782807
AH_TEMPLATE([ENABLE_BMAP_STATS], [Define to 1 to enable bitmap stats.])

e2fsck/dirinfo.c

Lines changed: 44 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,17 @@ struct dir_info_db {
2121
int size;
2222
struct dir_info *array;
2323
struct dir_info *last_lookup;
24+
#ifdef CONFIG_TDB
2425
char *tdb_fn;
2526
TDB_CONTEXT *tdb;
27+
#endif
2628
};
2729

2830
struct dir_info_iter {
2931
int i;
32+
#ifdef CONFIG_TDB
3033
TDB_DATA tdb_iter;
34+
#endif
3135
};
3236

3337
struct dir_info_ent {
@@ -38,6 +42,7 @@ struct dir_info_ent {
3842

3943
static void e2fsck_put_dir_info(e2fsck_t ctx, struct dir_info *dir);
4044

45+
#ifdef CONFIG_TDB
4146
static void setup_tdb(e2fsck_t ctx, ext2_ino_t num_dirs)
4247
{
4348
struct dir_info_db *db = ctx->dir_info;
@@ -79,6 +84,7 @@ static void setup_tdb(e2fsck_t ctx, ext2_ino_t num_dirs)
7984
O_RDWR | O_CREAT | O_TRUNC, 0600);
8085
close(fd);
8186
}
87+
#endif
8288

8389
static void setup_db(e2fsck_t ctx)
8490
{
@@ -98,6 +104,7 @@ static void setup_db(e2fsck_t ctx)
98104
if (retval)
99105
num_dirs = 1024; /* Guess */
100106

107+
#ifdef CONFIG_TDB
101108
setup_tdb(ctx, num_dirs);
102109

103110
if (db->tdb) {
@@ -106,6 +113,7 @@ static void setup_db(e2fsck_t ctx)
106113
#endif
107114
return;
108115
}
116+
#endif
109117

110118
db->size = num_dirs + 10;
111119
db->array = (struct dir_info *)
@@ -121,8 +129,7 @@ static void setup_db(e2fsck_t ctx)
121129
*/
122130
void e2fsck_add_dir_info(e2fsck_t ctx, ext2_ino_t ino, ext2_ino_t parent)
123131
{
124-
struct dir_info_db *db;
125-
struct dir_info *dir, ent, *old_array;
132+
struct dir_info *dir, *old_array;
126133
int i, j;
127134
errcode_t retval;
128135
unsigned long old_size;
@@ -132,7 +139,6 @@ void e2fsck_add_dir_info(e2fsck_t ctx, ext2_ino_t ino, ext2_ino_t parent)
132139
#endif
133140
if (!ctx->dir_info)
134141
setup_db(ctx);
135-
db = ctx->dir_info;
136142

137143
if (ctx->dir_info->count >= ctx->dir_info->size) {
138144
old_size = ctx->dir_info->size * sizeof(struct dir_info);
@@ -153,14 +159,17 @@ void e2fsck_add_dir_info(e2fsck_t ctx, ext2_ino_t ino, ext2_ino_t parent)
153159
ctx->dir_info->last_lookup = NULL;
154160
}
155161

156-
ent.ino = ino;
157-
ent.parent = parent;
158-
ent.dotdot = parent;
162+
#ifdef CONFIG_TDB
163+
if (ctx->dir_info->tdb) {
164+
struct dir_info ent;
159165

160-
if (db->tdb) {
166+
ent.ino = ino;
167+
ent.parent = parent;
168+
ent.dotdot = parent;
161169
e2fsck_put_dir_info(ctx, &ent);
162170
return;
163171
}
172+
#endif
164173

165174
/*
166175
* Normally, add_dir_info is called with each inode in
@@ -196,8 +205,6 @@ static struct dir_info *e2fsck_get_dir_info(e2fsck_t ctx, ext2_ino_t ino)
196205
{
197206
struct dir_info_db *db = ctx->dir_info;
198207
int low, high, mid;
199-
struct dir_info_ent *buf;
200-
static struct dir_info ret_dir_info;
201208

202209
if (!db)
203210
return 0;
@@ -206,8 +213,11 @@ static struct dir_info *e2fsck_get_dir_info(e2fsck_t ctx, ext2_ino_t ino)
206213
printf("e2fsck_get_dir_info %d...", ino);
207214
#endif
208215

216+
#ifdef CONFIG_TDB
209217
if (db->tdb) {
218+
static struct dir_info ret_dir_info;
210219
TDB_DATA key, data;
220+
struct dir_info_ent *buf;
211221

212222
key.dptr = (unsigned char *) &ino;
213223
key.dsize = sizeof(ext2_ino_t);
@@ -230,6 +240,7 @@ static struct dir_info *e2fsck_get_dir_info(e2fsck_t ctx, ext2_ino_t ino)
230240
free(data.dptr);
231241
return &ret_dir_info;
232242
}
243+
#endif
233244

234245
if (db->last_lookup && db->last_lookup->ino == ino)
235246
return db->last_lookup;
@@ -273,17 +284,21 @@ static struct dir_info *e2fsck_get_dir_info(e2fsck_t ctx, ext2_ino_t ino)
273284
return 0;
274285
}
275286

276-
static void e2fsck_put_dir_info(e2fsck_t ctx, struct dir_info *dir)
287+
static void e2fsck_put_dir_info(e2fsck_t ctx EXT2FS_NO_TDB_UNUSED,
288+
struct dir_info *dir EXT2FS_NO_TDB_UNUSED)
277289
{
290+
#ifdef CONFIG_TDB
278291
struct dir_info_db *db = ctx->dir_info;
279292
struct dir_info_ent buf;
280293
TDB_DATA key, data;
294+
#endif
281295

282296
#ifdef DIRINFO_DEBUG
283297
printf("e2fsck_put_dir_info (%d, %d, %d)...", dir->ino, dir->dotdot,
284298
dir->parent);
285299
#endif
286300

301+
#ifdef CONFIG_TDB
287302
if (!db->tdb)
288303
return;
289304

@@ -298,7 +313,7 @@ static void e2fsck_put_dir_info(e2fsck_t ctx, struct dir_info *dir)
298313
if (tdb_store(db->tdb, key, data, TDB_REPLACE) == -1) {
299314
printf("store failed: %s\n", tdb_errorstr(db->tdb));
300315
}
301-
return;
316+
#endif
302317
}
303318

304319
/*
@@ -307,12 +322,14 @@ static void e2fsck_put_dir_info(e2fsck_t ctx, struct dir_info *dir)
307322
void e2fsck_free_dir_info(e2fsck_t ctx)
308323
{
309324
if (ctx->dir_info) {
325+
#ifdef CONFIG_TDB
310326
if (ctx->dir_info->tdb)
311327
tdb_close(ctx->dir_info->tdb);
312328
if (ctx->dir_info->tdb_fn) {
313329
unlink(ctx->dir_info->tdb_fn);
314330
free(ctx->dir_info->tdb_fn);
315331
}
332+
#endif
316333
if (ctx->dir_info->array)
317334
ext2fs_free_mem(&ctx->dir_info->array);
318335
ctx->dir_info->array = 0;
@@ -334,21 +351,24 @@ int e2fsck_get_num_dirinfo(e2fsck_t ctx)
334351
struct dir_info_iter *e2fsck_dir_info_iter_begin(e2fsck_t ctx)
335352
{
336353
struct dir_info_iter *iter;
337-
struct dir_info_db *db = ctx->dir_info;
338354

339355
iter = e2fsck_allocate_memory(ctx, sizeof(struct dir_info_iter),
340356
"dir_info iterator");
341357

342-
if (db->tdb)
343-
iter->tdb_iter = tdb_firstkey(db->tdb);
358+
#ifdef CONFIG_TDB
359+
if (ctx->dir_info->tdb)
360+
iter->tdb_iter = tdb_firstkey(ctx->dir_info->tdb);
361+
#endif
344362

345363
return iter;
346364
}
347365

348366
void e2fsck_dir_info_iter_end(e2fsck_t ctx EXT2FS_ATTR((unused)),
349367
struct dir_info_iter *iter)
350368
{
369+
#ifdef CONFIG_TDB
351370
free(iter->tdb_iter.dptr);
371+
#endif
352372
ext2fs_free_mem(&iter);
353373
}
354374

@@ -357,33 +377,34 @@ void e2fsck_dir_info_iter_end(e2fsck_t ctx EXT2FS_ATTR((unused)),
357377
*/
358378
struct dir_info *e2fsck_dir_info_iter(e2fsck_t ctx, struct dir_info_iter *iter)
359379
{
360-
TDB_DATA data, key;
361-
struct dir_info_db *db = ctx->dir_info;
362-
struct dir_info_ent *buf;
363-
static struct dir_info ret_dir_info;
364-
365380
if (!ctx->dir_info || !iter)
366381
return 0;
367382

368-
if (db->tdb) {
383+
#ifdef CONFIG_TDB
384+
if (ctx->dir_info->tdb) {
385+
static struct dir_info ret_dir_info;
386+
struct dir_info_ent *buf;
387+
TDB_DATA data, key;
388+
369389
if (iter->tdb_iter.dptr == 0)
370390
return 0;
371391
key = iter->tdb_iter;
372-
data = tdb_fetch(db->tdb, key);
392+
data = tdb_fetch(ctx->dir_info->tdb, key);
373393
if (!data.dptr) {
374394
printf("iter fetch failed: %s\n",
375-
tdb_errorstr(db->tdb));
395+
tdb_errorstr(ctx->dir_info->tdb));
376396
return 0;
377397
}
378398
buf = (struct dir_info_ent *) data.dptr;
379399
ret_dir_info.ino = *((ext2_ino_t *) iter->tdb_iter.dptr);
380400
ret_dir_info.dotdot = buf->dotdot;
381401
ret_dir_info.parent = buf->parent;
382-
iter->tdb_iter = tdb_nextkey(db->tdb, key);
402+
iter->tdb_iter = tdb_nextkey(ctx->dir_info->tdb, key);
383403
free(key.dptr);
384404
free(data.dptr);
385405
return &ret_dir_info;
386406
}
407+
#endif
387408

388409
if (iter->i >= ctx->dir_info->count)
389410
return 0;

0 commit comments

Comments
 (0)