1
0
mirror of https://github.com/systemd/systemd synced 2026-03-11 15:44:47 +01:00

Compare commits

...

4 Commits

Author SHA1 Message Date
Lennart Poettering
f9b3afae96 repart: make sure to grow partition table after growing backing loopback file
This fixes the --size= switch, i.e. where we grow a disk image: after
growing it we need to expand the partition table so that its idea of the
the medium size matches the new reality. Otherwise our disk size
calculations in the subsequent steps might still use the original
ungrown size.

(This used to work, I guess this was borked when libfdisk learnt the
concept of "minimized" partition tables)
2021-03-19 18:11:26 +01:00
Michael Gisbers
6d18c13e79
correct incorrect command in NEWS (#19048)
* for /dev/vsock a file permission of 0o666 was mentioned but 0666 is probably better understood, so let's use that
* correct non existing command 'ip dev'
2021-03-19 11:38:53 +01:00
Sam Lunt
6f50c94dfd Wrong index in error message 2021-03-19 09:53:25 +00:00
Yu Watanabe
5cdb3f70eb udev: do not try to assign invalid ifname
Fixes #19038.
2021-03-19 09:52:21 +00:00
4 changed files with 53 additions and 15 deletions

4
NEWS
View File

@ -224,7 +224,7 @@ CHANGES WITH 248:
systemd.network files gained a new ActivationPolicy= setting which
allows configuring how the UP state of an interface shall be managed,
i.e. whether the interface is always upped, always downed, or may be
upped/downed by the user using "ip dev".
upped/downed by the user using "ip link set dev".
* The default for the Broadcast= setting in .network files has slightly
changed: the broadcast address will not be configured for wireguard
@ -251,7 +251,7 @@ CHANGES WITH 248:
be restored for individual services with NoExecPaths=/dev (or by allow-
listing and excluding /dev from ExecPaths=).
* Permissions for /dev/vsock are now set to 0o666, and /dev/vhost-vsock
* Permissions for /dev/vsock are now set to 0666, and /dev/vhost-vsock
and /dev/vhost-net are owned by the kvm group.
* The hardware database has been extended with a list of fingerprint

View File

@ -2510,8 +2510,8 @@ static int link_up_down(int argc, char *argv[], void *userdata) {
if (r < 0) {
char ifname[IF_NAMESIZE + 1];
return log_error_errno(r, "Failed to %s interface %s: %m",
argv[1], format_ifname_full(index, ifname, FORMAT_IFNAME_IFINDEX));
return log_error_errno(r, "Failed to bring %s interface %s: %m",
argv[0], format_ifname_full(index, ifname, FORMAT_IFNAME_IFINDEX));
}
}

View File

@ -3977,6 +3977,40 @@ static int find_root(char **ret, int *ret_fd) {
return log_error_errno(SYNTHETIC_ERRNO(ENODEV), "Failed to discover root block device.");
}
static int resize_pt(int fd) {
char procfs_path[STRLEN("/proc/self/fd/") + DECIMAL_STR_MAX(int)];
_cleanup_(fdisk_unref_contextp) struct fdisk_context *c = NULL;
int r;
/* After resizing the backing file we need to resize the partition table itself too, so that it takes
* possession of the enlarged backing file. For this it suffices to open the device with libfdisk and
* immediately write it again, with no changes. */
c = fdisk_new_context();
if (!c)
return log_oom();
xsprintf(procfs_path, "/proc/self/fd/%i", fd);
r = fdisk_assign_device(c, procfs_path, 0);
if (r < 0)
return log_error_errno(r, "Failed to open device '%s': %m", procfs_path);
r = fdisk_has_label(c);
if (r < 0)
return log_error_errno(r, "Failed to determine whether disk '%s' has a disk label: %m", procfs_path);
if (r == 0) {
log_debug("Not resizing partition table, as there currently is none.");
return 0;
}
r = fdisk_write_disklabel(c);
if (r < 0)
return log_error_errno(r, "Failed to write resized partition table: %m");
log_info("Resized partition table.");
return 1;
}
static int resize_backing_fd(const char *node, int *fd) {
char buf1[FORMAT_BYTES_MAX], buf2[FORMAT_BYTES_MAX];
_cleanup_close_ int writable_fd = -1;
@ -4029,6 +4063,10 @@ static int resize_backing_fd(const char *node, int *fd) {
/* Fallback to truncation, if fallocate() is not supported. */
log_debug("Backing file system does not support fallocate(), falling back to ftruncate().");
} else {
r = resize_pt(writable_fd);
if (r < 0)
return r;
if (st.st_size == 0) /* Likely regular file just created by us */
log_info("Allocated %s for '%s'.", buf2, node);
else
@ -4042,6 +4080,10 @@ static int resize_backing_fd(const char *node, int *fd) {
return log_error_errno(errno, "Failed to grow '%s' from %s to %s by truncation: %m",
node, buf1, buf2);
r = resize_pt(writable_fd);
if (r < 0)
return r;
if (st.st_size == 0) /* Likely regular file just created by us */
log_info("Sized '%s' to %s.", node, buf2);
else

View File

@ -441,8 +441,6 @@ static int link_config_apply_rtnl_settings(sd_netlink **rtnl, const link_config
static int link_config_generate_new_name(const link_config_ctx *ctx, const link_config *config, sd_device *device, const char **ret_name) {
unsigned name_type = NET_NAME_UNKNOWN;
const char *new_name = NULL;
NamePolicy policy;
int r;
assert(ctx);
@ -460,7 +458,8 @@ static int link_config_generate_new_name(const link_config_ctx *ctx, const link_
if (ctx->enable_name_policy && config->name_policy)
for (NamePolicy *p = config->name_policy; *p != _NAMEPOLICY_INVALID; p++) {
policy = *p;
const char *new_name = NULL;
NamePolicy policy = *p;
switch (policy) {
case NAMEPOLICY_KERNEL:
@ -496,16 +495,13 @@ static int link_config_generate_new_name(const link_config_ctx *ctx, const link_
default:
assert_not_reached("invalid policy");
}
if (ifname_valid(new_name))
break;
if (ifname_valid(new_name)) {
log_device_debug(device, "Policy *%s* yields \"%s\".", name_policy_to_string(policy), new_name);
*ret_name = new_name;
return 0;
}
}
if (new_name) {
log_device_debug(device, "Policy *%s* yields \"%s\".", name_policy_to_string(policy), new_name);
*ret_name = new_name;
return 0;
}
if (config->name) {
log_device_debug(device, "Policies didn't yield a name, using specified Name=%s.", config->name);
*ret_name = config->name;