homework: port home_create_directory_or_subvolume() to use HomeSetup

Let's migrate home_create_directory_or_subvolume() to also use HomeSetup
for storing its runtime objects we'd like to destroy in case of failure.

In the beginning this is just the root_fd, but later on we can add more.

No change in behaviour, just shifting things around.
This commit is contained in:
Lennart Poettering
2021-10-20 21:45:51 +02:00
parent f509ed4b61
commit e1aeaf27f5
3 changed files with 8 additions and 8 deletions

View File

@@ -80,16 +80,16 @@ int home_activate_directory(
return 0;
}
int home_create_directory_or_subvolume(UserRecord *h, UserRecord **ret_home) {
int home_create_directory_or_subvolume(UserRecord *h, HomeSetup *setup, UserRecord **ret_home) {
_cleanup_(rm_rf_subvolume_and_freep) char *temporary = NULL;
_cleanup_(user_record_unrefp) UserRecord *new_home = NULL;
_cleanup_close_ int root_fd = -1;
_cleanup_free_ char *d = NULL;
const char *ip;
int r;
assert(h);
assert(IN_SET(user_record_storage(h), USER_DIRECTORY, USER_SUBVOLUME));
assert(setup);
assert(ret_home);
assert_se(ip = user_record_image_path(h));
@@ -149,15 +149,15 @@ int home_create_directory_or_subvolume(UserRecord *h, UserRecord **ret_home) {
temporary = TAKE_PTR(d); /* Needs to be destroyed now */
root_fd = open(temporary, O_RDONLY|O_CLOEXEC|O_DIRECTORY|O_NOFOLLOW);
if (root_fd < 0)
setup->root_fd = open(temporary, O_RDONLY|O_CLOEXEC|O_DIRECTORY|O_NOFOLLOW);
if (setup->root_fd < 0)
return log_error_errno(errno, "Failed to open temporary home directory: %m");
r = home_populate(h, root_fd);
r = home_populate(h, setup->root_fd);
if (r < 0)
return r;
r = home_sync_and_statfs(root_fd, NULL);
r = home_sync_and_statfs(setup->root_fd, NULL);
if (r < 0)
return r;

View File

@@ -6,5 +6,5 @@
int home_setup_directory(UserRecord *h, HomeSetup *setup);
int home_activate_directory(UserRecord *h, HomeSetup *setup, PasswordCache *cache, UserRecord **ret_home);
int home_create_directory_or_subvolume(UserRecord *h, UserRecord **ret_home);
int home_create_directory_or_subvolume(UserRecord *h, HomeSetup *setup, UserRecord **ret_home);
int home_resize_directory(UserRecord *h, HomeSetupFlags flags, PasswordCache *cache, HomeSetup *setup, UserRecord **ret_home);

View File

@@ -1232,7 +1232,7 @@ static int home_create(UserRecord *h, UserRecord **ret_home) {
case USER_DIRECTORY:
case USER_SUBVOLUME:
r = home_create_directory_or_subvolume(h, &new_home);
r = home_create_directory_or_subvolume(h, &setup, &new_home);
break;
case USER_FSCRYPT: