From: Lennart Poettering Date: Thu, 19 Oct 2023 14:33:51 +0000 (+0200) Subject: iovec-util: make IOVEC_TOTAL_SIZE() a regular function X-Git-Tag: v255-rc1~186^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c24e0dbea1c2bb5eedcd7f335e3b6f1aafb79bad;p=thirdparty%2Fsystemd.git iovec-util: make IOVEC_TOTAL_SIZE() a regular function The function isn't necessarily fast (it's O(n)), and there's no reason to have it defined as inline function, since it's neither fast, nor entirely trivial. --- diff --git a/src/basic/iovec-util.c b/src/basic/iovec-util.c index 89c1af34f11..500ac33bbdb 100644 --- a/src/basic/iovec-util.c +++ b/src/basic/iovec-util.c @@ -3,6 +3,16 @@ #include "iovec-util.h" #include "string-util.h" +size_t iovec_total_size(const struct iovec *i, size_t n) { + size_t sum = 0; + + assert(i || n == 0); + + FOREACH_ARRAY(j, i, n) + sum += j->iov_len; + + return sum; +} char* set_iovec_string_field(struct iovec *iovec, size_t *n_iovec, const char *field, const char *value) { char *x; diff --git a/src/basic/iovec-util.h b/src/basic/iovec-util.h index 7ee72671c4d..670f57464ac 100644 --- a/src/basic/iovec-util.h +++ b/src/basic/iovec-util.h @@ -7,14 +7,7 @@ #include "macro.h" -static inline size_t IOVEC_TOTAL_SIZE(const struct iovec *i, size_t n) { - size_t r = 0; - - for (size_t j = 0; j < n; j++) - r += i[j].iov_len; - - return r; -} +size_t iovec_total_size(const struct iovec *i, size_t n); static inline bool IOVEC_INCREMENT(struct iovec *i, size_t n, size_t k) { /* Returns true if there is nothing else to send (bytes written cover all of the iovec), diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c index 8712d72acf0..58e23f7f76e 100644 --- a/src/journal/journald-server.c +++ b/src/journal/journald-server.c @@ -962,7 +962,7 @@ static void server_write_to_journal( return; } - log_debug_errno(r, "Failed to write entry to %s (%zu items, %zu bytes): %m", f->path, n, IOVEC_TOTAL_SIZE(iovec, n)); + log_debug_errno(r, "Failed to write entry to %s (%zu items, %zu bytes): %m", f->path, n, iovec_total_size(iovec, n)); if (!shall_try_append_again(f, r)) return; @@ -992,7 +992,7 @@ static void server_write_to_journal( if (r < 0) log_ratelimit_error_errno(r, FAILED_TO_WRITE_ENTRY_RATELIMIT, "Failed to write entry to %s (%zu items, %zu bytes) despite vacuuming, ignoring: %m", - f->path, n, IOVEC_TOTAL_SIZE(iovec, n)); + f->path, n, iovec_total_size(iovec, n)); else server_schedule_sync(s, priority); } diff --git a/src/libsystemd/sd-bus/bus-message.c b/src/libsystemd/sd-bus/bus-message.c index 150e7c9b9ec..f0818b801ca 100644 --- a/src/libsystemd/sd-bus/bus-message.c +++ b/src/libsystemd/sd-bus/bus-message.c @@ -1506,7 +1506,7 @@ _public_ int sd_bus_message_append_string_iovec( assert_return(iov || n == 0, -EINVAL); assert_return(!m->poisoned, -ESTALE); - size = IOVEC_TOTAL_SIZE(iov, n); + size = iovec_total_size(iov, n); r = sd_bus_message_append_string_space(m, size, &p); if (r < 0) @@ -2160,7 +2160,7 @@ _public_ int sd_bus_message_append_array_iovec( assert_return(iov || n == 0, -EINVAL); assert_return(!m->poisoned, -ESTALE); - size = IOVEC_TOTAL_SIZE(iov, n); + size = iovec_total_size(iov, n); r = sd_bus_message_append_array_space(m, type, size, &p); if (r < 0) diff --git a/src/libsystemd/sd-daemon/sd-daemon.c b/src/libsystemd/sd-daemon/sd-daemon.c index 5fccf0d7607..8986596b70d 100644 --- a/src/libsystemd/sd-daemon/sd-daemon.c +++ b/src/libsystemd/sd-daemon/sd-daemon.c @@ -585,7 +585,7 @@ static int pid_notify_with_fds_internal( send_ucred = false; } else { /* Unless we're using SOCK_STREAM, we expect to write all the contents immediately. */ - if (type != SOCK_STREAM && (size_t) n < IOVEC_TOTAL_SIZE(msghdr.msg_iov, msghdr.msg_iovlen)) + if (type != SOCK_STREAM && (size_t) n < iovec_total_size(msghdr.msg_iov, msghdr.msg_iovlen)) return -EIO; /* Make sure we only send fds and ucred once, even if we're using SOCK_STREAM. */ diff --git a/src/resolve/resolved-dnstls-gnutls.c b/src/resolve/resolved-dnstls-gnutls.c index acdad6fa910..61f38ef4b4c 100644 --- a/src/resolve/resolved-dnstls-gnutls.c +++ b/src/resolve/resolved-dnstls-gnutls.c @@ -171,7 +171,7 @@ ssize_t dnstls_stream_writev(DnsStream *stream, const struct iovec *iov, size_t assert(stream->encrypted); assert(stream->dnstls_data.session); assert(iov); - assert(IOVEC_TOTAL_SIZE(iov, iovcnt) > 0); + assert(iovec_total_size(iov, iovcnt) > 0); gnutls_record_cork(stream->dnstls_data.session); diff --git a/src/resolve/resolved-dnstls-openssl.c b/src/resolve/resolved-dnstls-openssl.c index 4a0132ad3d8..b217417a1ac 100644 --- a/src/resolve/resolved-dnstls-openssl.c +++ b/src/resolve/resolved-dnstls-openssl.c @@ -322,14 +322,14 @@ ssize_t dnstls_stream_writev(DnsStream *stream, const struct iovec *iov, size_t assert(stream->encrypted); assert(stream->dnstls_data.ssl); assert(iov); - assert(IOVEC_TOTAL_SIZE(iov, iovcnt) > 0); + assert(iovec_total_size(iov, iovcnt) > 0); if (iovcnt == 1) return dnstls_stream_write(stream, iov[0].iov_base, iov[0].iov_len); /* As of now, OpenSSL can not accumulate multiple writes, so join into a single buffer. Suboptimal, but better than multiple SSL_write calls. */ - count = IOVEC_TOTAL_SIZE(iov, iovcnt); + count = iovec_total_size(iov, iovcnt); buf = new(char, count); for (size_t i = 0, pos = 0; i < iovcnt; pos += iov[i].iov_len, i++) memcpy(buf + pos, iov[i].iov_base, iov[i].iov_len);