[systemd-commits] 3 commits - TODO src/machine src/shared
Lennart Poettering
lennart at kemper.freedesktop.org
Wed Jan 7 05:49:33 PST 2015
TODO | 2
src/machine/machinectl.c | 9 +--
src/shared/btrfs-util.c | 127 +++++++++++++++++++++++++++++++++++------------
src/shared/ptyfwd.c | 52 +++++++------------
src/shared/ptyfwd.h | 6 +-
5 files changed, 125 insertions(+), 71 deletions(-)
New commits:
commit 5b728e6ba17c39e0787ad81b96a5582f4390f091
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Jan 7 14:49:27 2015 +0100
Update TODO
diff --git a/TODO b/TODO
index 3aeef3c..a237e0c 100644
--- a/TODO
+++ b/TODO
@@ -57,6 +57,8 @@ Features:
* systemd-nspawn -x should support ephemeral instances of gpt images
+* move machinectl's mount and copy commands into machined
+
* hostnamectl: show root image uuid
* sysfs set api in libudev is not const
commit da054c3782f25b3b18243f6c76dcfcf90ba70274
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Jan 7 14:46:45 2015 +0100
ptyfwd: simplify how we handle vhangups a bit
diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c
index 7e995ca..be3896a 100644
--- a/src/machine/machinectl.c
+++ b/src/machine/machinectl.c
@@ -1240,13 +1240,14 @@ static int on_machine_removed(sd_bus *bus, sd_bus_message *m, void *userdata, sd
if (*forward) {
/* If the forwarder is already initialized, tell it to
- * exit on the next hangup */
+ * exit on the next vhangup(), so that we still flush
+ * out what might be queued and exit then. */
- r = pty_forward_set_repeat(*forward, false);
+ r = pty_forward_set_ignore_vhangup(*forward, false);
if (r >= 0)
return 0;
- log_error_errno(r, "Failed to set repeat flag: %m");
+ log_error_errno(r, "Failed to set ignore_vhangup flag: %m");
}
/* On error, or when the forwarder is not initialized yet, quit immediately */
@@ -1341,7 +1342,7 @@ static int login_machine(int argc, char *argv[], void *userdata) {
return log_error_errno(r, "Failed to run event loop: %m");
pty_forward_get_last_char(forward, &last_char);
- machine_died = pty_forward_get_repeat(forward) == 0;
+ machine_died = pty_forward_get_ignore_vhangup(forward) == 0;
forward = pty_forward_free(forward);
diff --git a/src/shared/ptyfwd.c b/src/shared/ptyfwd.c
index db2445c..a780f7d 100644
--- a/src/shared/ptyfwd.c
+++ b/src/shared/ptyfwd.c
@@ -52,9 +52,9 @@ struct PTYForward {
bool master_readable:1;
bool master_writable:1;
bool master_hangup:1;
- bool master_suppressed_hangup:1;
- bool repeat:1;
+ /* Continue reading after hangup? */
+ bool ignore_vhangup:1;
bool last_char_set:1;
char last_char;
@@ -171,22 +171,16 @@ static int shovel(PTYForward *f) {
k = read(f->master, f->out_buffer + f->out_buffer_full, LINE_MAX - f->out_buffer_full);
if (k < 0) {
- if (errno == EAGAIN)
- f->master_readable = false;
-
- else if (errno == EIO && f->repeat) {
-
- /* Note that EIO on the master device
- * might be cause by vhangup() or
- * temporary closing of everything on
- * the other side, we treat it like
- * EAGAIN here and try again, unless
- * repeat is off. */
+ /* Note that EIO on the master device
+ * might be caused by vhangup() or
+ * temporary closing of everything on
+ * the other side, we treat it like
+ * EAGAIN here and try again, unless
+ * ignore_vhangup is off. */
+ if (errno == EAGAIN || (errno == EIO && f->ignore_vhangup))
f->master_readable = false;
- f->master_suppressed_hangup = true;
-
- } else if (errno == EPIPE || errno == ECONNRESET || errno == EIO) {
+ else if (errno == EPIPE || errno == ECONNRESET || errno == EIO) {
f->master_readable = f->master_writable = false;
f->master_hangup = true;
@@ -250,8 +244,6 @@ static int on_master_event(sd_event_source *e, int fd, uint32_t revents, void *u
assert(fd >= 0);
assert(fd == f->master);
- f->master_suppressed_hangup = false;
-
if (revents & (EPOLLIN|EPOLLHUP))
f->master_readable = true;
@@ -306,7 +298,7 @@ static int on_sigwinch_event(sd_event_source *e, const struct signalfd_siginfo *
return 0;
}
-int pty_forward_new(sd_event *event, int master, bool repeat, PTYForward **ret) {
+int pty_forward_new(sd_event *event, int master, bool ignore_vhangup, PTYForward **ret) {
_cleanup_(pty_forward_freep) PTYForward *f = NULL;
struct winsize ws;
int r;
@@ -315,7 +307,7 @@ int pty_forward_new(sd_event *event, int master, bool repeat, PTYForward **ret)
if (!f)
return -ENOMEM;
- f->repeat = repeat;
+ f->ignore_vhangup = ignore_vhangup;
if (event)
f->event = sd_event_ref(event);
@@ -423,23 +415,19 @@ int pty_forward_get_last_char(PTYForward *f, char *ch) {
return 0;
}
-int pty_forward_set_repeat(PTYForward *f, bool repeat) {
+int pty_forward_set_ignore_vhangup(PTYForward *f, bool ignore_vhangup) {
int r;
assert(f);
- if (f->repeat == repeat)
+ if (f->ignore_vhangup == ignore_vhangup)
return 0;
- f->repeat = repeat;
-
- /* Are we currently in a suppress hangup phase? If so, let's
- * immediately terminate things */
- if (!f->repeat && f->master_suppressed_hangup) {
+ f->ignore_vhangup = ignore_vhangup;
+ if (!f->ignore_vhangup) {
- /* Let's try to read again from the master fd, and if
- * it is this will now cause termination of the
- * session. */
+ /* We shall now react to vhangup()s? Let's check
+ * immediately if we might be in one */
f->master_readable = true;
r = shovel(f);
@@ -450,8 +438,8 @@ int pty_forward_set_repeat(PTYForward *f, bool repeat) {
return 0;
}
-int pty_forward_get_repeat(PTYForward *f) {
+int pty_forward_get_ignore_vhangup(PTYForward *f) {
assert(f);
- return f->repeat;
+ return f->ignore_vhangup;
}
diff --git a/src/shared/ptyfwd.h b/src/shared/ptyfwd.h
index d557dee..d65b66a 100644
--- a/src/shared/ptyfwd.h
+++ b/src/shared/ptyfwd.h
@@ -28,12 +28,12 @@
typedef struct PTYForward PTYForward;
-int pty_forward_new(sd_event *event, int master, bool repeat, PTYForward **f);
+int pty_forward_new(sd_event *event, int master, bool ignore_vhangup, PTYForward **f);
PTYForward *pty_forward_free(PTYForward *f);
int pty_forward_get_last_char(PTYForward *f, char *ch);
-int pty_forward_set_repeat(PTYForward *f, bool repeat);
-int pty_forward_get_repeat(PTYForward *f);
+int pty_forward_set_ignore_vhangup(PTYForward *f, bool ignore_vhangup);
+int pty_forward_get_ignore_vhangup(PTYForward *f);
DEFINE_TRIVIAL_CLEANUP_FUNC(PTYForward*, pty_forward_free);
commit 5743a5852d2ab6ad7f589c255afcfdf523d60ba8
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Jan 7 14:43:10 2015 +0100
btrfs-util: rework how we iterate through the results of the TREE_SEARCH results
Let's introduce some syntactic sugar with iteration macros, and add
correct key increment calls.
diff --git a/src/shared/btrfs-util.c b/src/shared/btrfs-util.c
index e648121..bd100ee 100644
--- a/src/shared/btrfs-util.c
+++ b/src/shared/btrfs-util.c
@@ -338,6 +338,77 @@ int btrfs_subvol_get_id_fd(int fd, uint64_t *ret) {
return 0;
}
+static bool btrfs_ioctl_search_args_inc(struct btrfs_ioctl_search_args *args) {
+ assert(args);
+
+ /* the objectid, type, offset together make up the btrfs key,
+ * which is considered a single 136byte integer when
+ * comparing. This call increases the counter by one, dealing
+ * with the overflow between the overflows */
+
+ if (args->key.min_offset < (uint64_t) -1) {
+ args->key.min_offset++;
+ return true;
+ }
+
+ if (args->key.min_type < (uint8_t) -1) {
+ args->key.min_type++;
+ args->key.min_offset = 0;
+ return true;
+ }
+
+ if (args->key.min_objectid < (uint64_t) -1) {
+ args->key.min_objectid++;
+ args->key.min_offset = 0;
+ args->key.min_type = 0;
+ return true;
+ }
+
+ return 0;
+}
+
+static void btrfs_ioctl_search_args_set(struct btrfs_ioctl_search_args *args, const struct btrfs_ioctl_search_header *h) {
+ assert(args);
+ assert(h);
+
+ args->key.min_objectid = h->objectid;
+ args->key.min_type = h->type;
+ args->key.min_offset = h->offset;
+}
+
+static int btrfs_ioctl_search_args_compare(const struct btrfs_ioctl_search_args *args) {
+ assert(args);
+
+ /* Compare min and max */
+
+ if (args->key.min_objectid < args->key.max_objectid)
+ return -1;
+ if (args->key.min_objectid > args->key.max_objectid)
+ return 1;
+
+ if (args->key.min_type < args->key.max_type)
+ return -1;
+ if (args->key.min_type > args->key.max_type)
+ return 1;
+
+ if (args->key.min_offset < args->key.max_offset)
+ return -1;
+ if (args->key.min_offset > args->key.max_offset)
+ return 1;
+
+ return 0;
+}
+
+#define FOREACH_BTRFS_IOCTL_SEARCH_HEADER(i, sh, args) \
+ for ((i) = 0, \
+ (sh) = (const struct btrfs_ioctl_search_header*) (args).buf; \
+ (i) < (args).key.nr_items; \
+ (i)++, \
+ (sh) = (const struct btrfs_ioctl_search_header*) ((uint8_t*) (sh) + sizeof(struct btrfs_ioctl_search_header) + (sh)->len))
+
+#define BTRFS_IOCTL_SEARCH_HEADER_BODY(sh) \
+ ((void*) ((uint8_t*) sh + sizeof(struct btrfs_ioctl_search_header)))
+
int btrfs_subvol_get_info_fd(int fd, BtrfsSubvolInfo *ret) {
struct btrfs_ioctl_search_args args = {
/* Tree of tree roots */
@@ -347,9 +418,10 @@ int btrfs_subvol_get_info_fd(int fd, BtrfsSubvolInfo *ret) {
.key.min_type = BTRFS_ROOT_ITEM_KEY,
.key.max_type = BTRFS_ROOT_ITEM_KEY,
- /* No restrictions on the other components */
.key.min_offset = 0,
.key.max_offset = (uint64_t) -1,
+
+ /* No restrictions on the other components */
.key.min_transid = 0,
.key.max_transid = (uint64_t) -1,
};
@@ -367,7 +439,7 @@ int btrfs_subvol_get_info_fd(int fd, BtrfsSubvolInfo *ret) {
args.key.min_objectid = args.key.max_objectid = subvol_id;
- for (;;) {
+ while (btrfs_ioctl_search_args_compare(&args) <= 0) {
const struct btrfs_ioctl_search_header *sh;
unsigned i;
@@ -378,25 +450,23 @@ int btrfs_subvol_get_info_fd(int fd, BtrfsSubvolInfo *ret) {
if (args.key.nr_items <= 0)
break;
- for (i = 0,
- sh = (const struct btrfs_ioctl_search_header*) args.buf;
- i < args.key.nr_items;
- i++,
- args.key.min_type = sh->type,
- args.key.min_offset = sh->offset,
- args.key.min_objectid = sh->objectid,
- sh = (const struct btrfs_ioctl_search_header*) ((uint8_t*) sh + sizeof(struct btrfs_ioctl_search_header) + sh->len)) {
+ FOREACH_BTRFS_IOCTL_SEARCH_HEADER(i, sh, args) {
const struct btrfs_root_item *ri;
+ /* Make sure we start the next search at least from this entry */
+ btrfs_ioctl_search_args_set(&args, sh);
+
if (sh->objectid != subvol_id)
continue;
if (sh->type != BTRFS_ROOT_ITEM_KEY)
continue;
+
+ /* Older versions of the struct lacked the otime setting */
if (sh->len < offsetof(struct btrfs_root_item, otime) + sizeof(struct btrfs_timespec))
continue;
- ri = (const struct btrfs_root_item *)(args.buf + sizeof(struct btrfs_ioctl_search_header));
+ ri = BTRFS_IOCTL_SEARCH_HEADER_BODY(sh);
ret->otime = (usec_t) le64toh(ri->otime.sec) * USEC_PER_SEC +
(usec_t) le32toh(ri->otime.nsec) / NSEC_PER_USEC;
@@ -412,8 +482,8 @@ int btrfs_subvol_get_info_fd(int fd, BtrfsSubvolInfo *ret) {
goto finish;
}
- args.key.min_offset++;
- if (!args.key.min_offset) /* overflow */
+ /* Increase search key by one, to read the next item, if we can. */
+ if (!btrfs_ioctl_search_args_inc(&args))
break;
}
@@ -430,13 +500,14 @@ int btrfs_subvol_get_quota_fd(int fd, BtrfsQuotaInfo *ret) {
/* Tree of quota items */
.key.tree_id = BTRFS_QUOTA_TREE_OBJECTID,
+ /* The object ID is always 0 */
+ .key.min_objectid = 0,
+ .key.max_objectid = 0,
+
/* Look precisely for the quota items */
.key.min_type = BTRFS_QGROUP_STATUS_KEY,
.key.max_type = BTRFS_QGROUP_LIMIT_KEY,
- .key.min_objectid = 0,
- .key.max_objectid = 0,
-
/* No restrictions on the other components */
.key.min_transid = 0,
.key.max_transid = (uint64_t) -1,
@@ -455,7 +526,7 @@ int btrfs_subvol_get_quota_fd(int fd, BtrfsQuotaInfo *ret) {
args.key.min_offset = args.key.max_offset = subvol_id;
- for (;;) {
+ while (btrfs_ioctl_search_args_compare(&args) <= 0) {
const struct btrfs_ioctl_search_header *sh;
unsigned i;
@@ -466,26 +537,18 @@ int btrfs_subvol_get_quota_fd(int fd, BtrfsQuotaInfo *ret) {
if (args.key.nr_items <= 0)
break;
- for (i = 0,
- sh = (const struct btrfs_ioctl_search_header*) args.buf;
- i < args.key.nr_items;
- i++,
- args.key.min_type = sh->type,
- args.key.min_offset = sh->offset,
- args.key.min_objectid = sh->objectid,
- sh = (const struct btrfs_ioctl_search_header*) ((uint8_t*) sh + sizeof(struct btrfs_ioctl_search_header) + sh->len)) {
+ FOREACH_BTRFS_IOCTL_SEARCH_HEADER(i, sh, args) {
- const void *body;
+ /* Make sure we start the next search at least from this entry */
+ btrfs_ioctl_search_args_set(&args, sh);
if (sh->objectid != 0)
continue;
if (sh->offset != subvol_id)
continue;
- body = (uint8_t*) sh + sizeof(struct btrfs_ioctl_search_header);
-
if (sh->type == BTRFS_QGROUP_INFO_KEY) {
- const struct btrfs_qgroup_info_item *qii = body;
+ const struct btrfs_qgroup_info_item *qii = BTRFS_IOCTL_SEARCH_HEADER_BODY(sh);
ret->referred = le64toh(qii->rfer);
ret->exclusive = le64toh(qii->excl);
@@ -493,7 +556,7 @@ int btrfs_subvol_get_quota_fd(int fd, BtrfsQuotaInfo *ret) {
found_info = true;
} else if (sh->type == BTRFS_QGROUP_LIMIT_KEY) {
- const struct btrfs_qgroup_limit_item *qli = body;
+ const struct btrfs_qgroup_limit_item *qli = BTRFS_IOCTL_SEARCH_HEADER_BODY(sh);
ret->referred_max = le64toh(qli->max_rfer);
ret->exclusive_max = le64toh(qli->max_excl);
@@ -510,8 +573,8 @@ int btrfs_subvol_get_quota_fd(int fd, BtrfsQuotaInfo *ret) {
goto finish;
}
- args.key.min_offset++;
- if (!args.key.min_offset)
+ /* Increase search key by one, to read the next item, if we can. */
+ if (!btrfs_ioctl_search_args_inc(&args))
break;
}
More information about the systemd-commits
mailing list