Skip to content

Commit ad4eec6

Browse files
Eric Sandeentytso
authored andcommitted
ext4: allow specifying external journal by pathname mount option
It's always been a hassle that if an external journal's device number changes, the filesystem won't mount. And since boot-time enumeration can change, device number changes aren't unusual. The current mechanism to update the journal location is by passing in a mount option w/ a new devnum, but that's a hassle; it's a manual approach, fixing things after the fact. Adding a mount option, "-o journal_path=/dev/$DEVICE" would help, since then we can do i.e. # mount -o journal_path=/dev/disk/by-label/$JOURNAL_LABEL ... and it'll mount even if the devnum has changed, as shown here: # losetup /dev/loop0 journalfile # mke2fs -L mylabel-journal -O journal_dev /dev/loop0 # mkfs.ext4 -L mylabel -J device=/dev/loop0 /dev/sdb1 Change the journal device number: # losetup -d /dev/loop0 # losetup /dev/loop1 journalfile And today it will fail: # mount /dev/sdb1 /mnt/test mount: wrong fs type, bad option, bad superblock on /dev/sdb1, missing codepage or helper program, or other error In some cases useful info is found in syslog - try dmesg | tail or so # dmesg | tail -n 1 [17343.240702] EXT4-fs (sdb1): error: couldn't read superblock of external journal But with this new mount option, we can specify the new path: # mount -o journal_path=/dev/loop1 /dev/sdb1 /mnt/test # (which does update the encoded device number, incidentally): # umount /dev/sdb1 # dumpe2fs -h /dev/sdb1 | grep "Journal device" dumpe2fs 1.41.12 (17-May-2010) Journal device: 0x0701 But best of all we can just always mount by journal-path, and it'll always work: # mount -o journal_path=/dev/disk/by-label/mylabel-journal /dev/sdb1 /mnt/test # So the journal_path option can be specified in fstab, and as long as the disk is available somewhere, and findable by label (or by UUID), we can mount. Signed-off-by: Eric Sandeen <[email protected]> Signed-off-by: "Theodore Ts'o" <[email protected]> Reviewed-by: Jan Kara <[email protected]> Reviewed-by: Carlos Maiolino <[email protected]>
1 parent bdfb6ff commit ad4eec6

File tree

2 files changed

+48
-6
lines changed

2 files changed

+48
-6
lines changed

Documentation/filesystems/ext4.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,12 @@ journal_async_commit Commit block can be written to disk without waiting
144144
mount the device. This will enable 'journal_checksum'
145145
internally.
146146

147+
journal_path=path
147148
journal_dev=devnum When the external journal device's major/minor numbers
148-
have changed, this option allows the user to specify
149+
have changed, these options allow the user to specify
149150
the new journal location. The journal device is
150-
identified through its new major/minor numbers encoded
151-
in devnum.
151+
identified through either its new major/minor numbers
152+
encoded in devnum, or via a path to the device.
152153

153154
norecovery Don't load the journal on mounting. Note that
154155
noload if the filesystem was not unmounted cleanly,

fs/ext4/super.c

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,8 +1134,8 @@ enum {
11341134
Opt_nouid32, Opt_debug, Opt_removed,
11351135
Opt_user_xattr, Opt_nouser_xattr, Opt_acl, Opt_noacl,
11361136
Opt_auto_da_alloc, Opt_noauto_da_alloc, Opt_noload,
1137-
Opt_commit, Opt_min_batch_time, Opt_max_batch_time,
1138-
Opt_journal_dev, Opt_journal_checksum, Opt_journal_async_commit,
1137+
Opt_commit, Opt_min_batch_time, Opt_max_batch_time, Opt_journal_dev,
1138+
Opt_journal_path, Opt_journal_checksum, Opt_journal_async_commit,
11391139
Opt_abort, Opt_data_journal, Opt_data_ordered, Opt_data_writeback,
11401140
Opt_data_err_abort, Opt_data_err_ignore,
11411141
Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota,
@@ -1179,6 +1179,7 @@ static const match_table_t tokens = {
11791179
{Opt_min_batch_time, "min_batch_time=%u"},
11801180
{Opt_max_batch_time, "max_batch_time=%u"},
11811181
{Opt_journal_dev, "journal_dev=%u"},
1182+
{Opt_journal_path, "journal_path=%s"},
11821183
{Opt_journal_checksum, "journal_checksum"},
11831184
{Opt_journal_async_commit, "journal_async_commit"},
11841185
{Opt_abort, "abort"},
@@ -1338,6 +1339,7 @@ static int clear_qf_name(struct super_block *sb, int qtype)
13381339
#define MOPT_NO_EXT2 0x0100
13391340
#define MOPT_NO_EXT3 0x0200
13401341
#define MOPT_EXT4_ONLY (MOPT_NO_EXT2 | MOPT_NO_EXT3)
1342+
#define MOPT_STRING 0x0400
13411343

13421344
static const struct mount_opts {
13431345
int token;
@@ -1387,6 +1389,7 @@ static const struct mount_opts {
13871389
{Opt_resuid, 0, MOPT_GTE0},
13881390
{Opt_resgid, 0, MOPT_GTE0},
13891391
{Opt_journal_dev, 0, MOPT_GTE0},
1392+
{Opt_journal_path, 0, MOPT_STRING},
13901393
{Opt_journal_ioprio, 0, MOPT_GTE0},
13911394
{Opt_data_journal, EXT4_MOUNT_JOURNAL_DATA, MOPT_NO_EXT2 | MOPT_DATAJ},
13921395
{Opt_data_ordered, EXT4_MOUNT_ORDERED_DATA, MOPT_NO_EXT2 | MOPT_DATAJ},
@@ -1480,7 +1483,7 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token,
14801483
return -1;
14811484
}
14821485

1483-
if (args->from && match_int(args, &arg))
1486+
if (args->from && !(m->flags & MOPT_STRING) && match_int(args, &arg))
14841487
return -1;
14851488
if (args->from && (m->flags & MOPT_GTE0) && (arg < 0))
14861489
return -1;
@@ -1544,6 +1547,44 @@ static int handle_mount_opt(struct super_block *sb, char *opt, int token,
15441547
return -1;
15451548
}
15461549
*journal_devnum = arg;
1550+
} else if (token == Opt_journal_path) {
1551+
char *journal_path;
1552+
struct inode *journal_inode;
1553+
struct path path;
1554+
int error;
1555+
1556+
if (is_remount) {
1557+
ext4_msg(sb, KERN_ERR,
1558+
"Cannot specify journal on remount");
1559+
return -1;
1560+
}
1561+
journal_path = match_strdup(&args[0]);
1562+
if (!journal_path) {
1563+
ext4_msg(sb, KERN_ERR, "error: could not dup "
1564+
"journal device string");
1565+
return -1;
1566+
}
1567+
1568+
error = kern_path(journal_path, LOOKUP_FOLLOW, &path);
1569+
if (error) {
1570+
ext4_msg(sb, KERN_ERR, "error: could not find "
1571+
"journal device path: error %d", error);
1572+
kfree(journal_path);
1573+
return -1;
1574+
}
1575+
1576+
journal_inode = path.dentry->d_inode;
1577+
if (!S_ISBLK(journal_inode->i_mode)) {
1578+
ext4_msg(sb, KERN_ERR, "error: journal path %s "
1579+
"is not a block device", journal_path);
1580+
path_put(&path);
1581+
kfree(journal_path);
1582+
return -1;
1583+
}
1584+
1585+
*journal_devnum = new_encode_dev(journal_inode->i_rdev);
1586+
path_put(&path);
1587+
kfree(journal_path);
15471588
} else if (token == Opt_journal_ioprio) {
15481589
if (arg > 7) {
15491590
ext4_msg(sb, KERN_ERR, "Invalid journal IO priority"

0 commit comments

Comments
 (0)