Skip to content

Commit bc5890c

Browse files
committed
homework: use HomeSetup in home_create_luks() too
We use it for all other LUKS operations these days, and for all home_create_xyz() calls for other backends, let's use it for the LUKS backend too.
1 parent 93a5fe3 commit bc5890c

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

src/home/homework-luks.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1992,6 +1992,7 @@ static int home_truncate(
19921992

19931993
int home_create_luks(
19941994
UserRecord *h,
1995+
HomeSetup *setup,
19951996
const PasswordCache *cache,
19961997
char **effective_passwords,
19971998
UserRecord **ret_home) {
@@ -2004,13 +2005,14 @@ int home_create_luks(
20042005
sd_id128_t partition_uuid, fs_uuid, luks_uuid, disk_uuid;
20052006
_cleanup_(loop_device_unrefp) LoopDevice *loop = NULL;
20062007
_cleanup_(sym_crypt_freep) struct crypt_device *cd = NULL;
2007-
_cleanup_close_ int image_fd = -1, root_fd = -1;
2008+
_cleanup_close_ int image_fd = -1;
20082009
const char *fstype, *ip;
20092010
struct statfs sfs;
20102011
int r;
20112012

20122013
assert(h);
20132014
assert(h->storage < 0 || h->storage == USER_LUKS);
2015+
assert(setup);
20142016
assert(ret_home);
20152017

20162018
r = dlopen_cryptsetup();
@@ -2256,17 +2258,17 @@ int home_create_luks(
22562258
goto fail;
22572259
}
22582260

2259-
root_fd = open(subdir, O_RDONLY|O_CLOEXEC|O_DIRECTORY|O_NOFOLLOW);
2260-
if (root_fd < 0) {
2261+
setup->root_fd = open(subdir, O_RDONLY|O_CLOEXEC|O_DIRECTORY|O_NOFOLLOW);
2262+
if (setup->root_fd < 0) {
22612263
r = log_error_errno(errno, "Failed to open user directory in mounted image file: %m");
22622264
goto fail;
22632265
}
22642266

2265-
r = home_populate(h, root_fd);
2267+
r = home_populate(h, setup->root_fd);
22662268
if (r < 0)
22672269
goto fail;
22682270

2269-
r = home_sync_and_statfs(root_fd, &sfs);
2271+
r = home_sync_and_statfs(setup->root_fd, &sfs);
22702272
if (r < 0)
22712273
goto fail;
22722274

@@ -2296,12 +2298,12 @@ int home_create_luks(
22962298
}
22972299

22982300
if (user_record_luks_offline_discard(h)) {
2299-
r = run_fitrim(root_fd);
2301+
r = run_fitrim(setup->root_fd);
23002302
if (r < 0)
23012303
goto fail;
23022304
}
23032305

2304-
root_fd = safe_close(root_fd);
2306+
setup->root_fd = safe_close(setup->root_fd);
23052307

23062308
r = umount_verbose(LOG_ERR, HOME_RUNTIME_WORK_DIR, UMOUNT_NOFOLLOW);
23072309
if (r < 0)
@@ -2370,7 +2372,7 @@ int home_create_luks(
23702372

23712373
fail:
23722374
/* Let's close all files before we unmount the file system, to avoid EBUSY */
2373-
root_fd = safe_close(root_fd);
2375+
setup->root_fd = safe_close(setup->root_fd);
23742376

23752377
if (mounted)
23762378
(void) umount_verbose(LOG_WARNING, HOME_RUNTIME_WORK_DIR, UMOUNT_NOFOLLOW);

src/home/homework-luks.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ int home_trim_luks(UserRecord *h);
1313

1414
int home_store_header_identity_luks(UserRecord *h, HomeSetup *setup, UserRecord *old_home);
1515

16-
int home_create_luks(UserRecord *h, const PasswordCache *cache, char **effective_passwords, UserRecord **ret_home);
16+
int home_create_luks(UserRecord *h, HomeSetup *setup, const PasswordCache *cache, char **effective_passwords, UserRecord **ret_home);
1717

1818
int home_get_state_luks(UserRecord *h, HomeSetup *setup);
1919

src/home/homework.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1279,7 +1279,7 @@ static int home_create(UserRecord *h, UserRecord **ret_home) {
12791279
switch (user_record_storage(h)) {
12801280

12811281
case USER_LUKS:
1282-
r = home_create_luks(h, &cache, effective_passwords, &new_home);
1282+
r = home_create_luks(h, &setup, &cache, effective_passwords, &new_home);
12831283
break;
12841284

12851285
case USER_DIRECTORY:

0 commit comments

Comments
 (0)