From: Xavi Hernandez Date: Tue, 11 Feb 2025 15:13:09 +0000 (+0100) Subject: libcephfs_proxy: reuse proxy_link_{read|write} X-Git-Tag: v20.3.0~362^2~17 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=9e0a231d8c3ed0b301ed8a10417ded2daa77c439;p=ceph.git libcephfs_proxy: reuse proxy_link_{read|write} Functions proxy_link_read() and proxy_link_write() were unused. They are slightly modified to be used for the negotiation communication. Signed-off-by: Xavi Hernandez --- diff --git a/src/libcephfs_proxy/proxy_link.c b/src/libcephfs_proxy/proxy_link.c index 20d9086ffa9d..506b4dd6bbff 100644 --- a/src/libcephfs_proxy/proxy_link.c +++ b/src/libcephfs_proxy/proxy_link.c @@ -55,6 +55,62 @@ static int32_t proxy_link_prepare(struct sockaddr_un *addr, const char *path) return sd; } +static int32_t proxy_link_read(proxy_link_t *link, int32_t sd, void *buffer, + int32_t size) +{ + ssize_t len; + + while (size > 0) { + len = read(sd, buffer, size); + if (len < 0) { + if (errno == EINTR) { + if (link->stop(link)) { + return -EINTR; + } + continue; + } + return proxy_log(LOG_ERR, errno, + "Failed to read from socket"); + } + if (len == 0) { + return proxy_log(LOG_ERR, EPIPE, "Partial read"); + } + + buffer += len; + size -= len; + } + + return 0; +} + +static int32_t proxy_link_write(proxy_link_t *link, int32_t sd, void *buffer, + int32_t size) +{ + ssize_t len; + + while (size > 0) { + len = write(sd, buffer, size); + if (len < 0) { + if (errno == EINTR) { + if (link->stop(link)) { + return -EINTR; + } + continue; + } + return proxy_log(LOG_ERR, errno, + "Failed to write to socket"); + } + if (len == 0) { + return proxy_log(LOG_ERR, EPIPE, "Partial write"); + } + + buffer += len; + size -= len; + } + + return 0; +} + int32_t proxy_link_client(proxy_link_t *link, const char *path, proxy_link_stop_t stop) { @@ -149,59 +205,6 @@ done: return err; } -int32_t proxy_link_read(proxy_link_t *link, int32_t sd, void *buffer, - int32_t size) -{ - ssize_t len; - - do { - len = read(sd, buffer, size); - if (len < 0) { - if (errno == EINTR) { - if (link->stop(link)) { - return -EINTR; - } - continue; - } - return proxy_log(LOG_ERR, errno, - "Failed to read from socket"); - } - } while (len < 0); - - return len; -} - -int32_t proxy_link_write(proxy_link_t *link, int32_t sd, void *buffer, - int32_t size) -{ - ssize_t len; - int32_t total; - - total = size; - while (total > 0) { - len = write(sd, buffer, total); - if (len < 0) { - if (errno == EINTR) { - if (link->stop(link)) { - return -EINTR; - } - continue; - } - return proxy_log(LOG_ERR, errno, - "Failed to write to socket"); - } - if (len == 0) { - return proxy_log(LOG_ERR, ENOBUFS, - "No data written to socket"); - } - - buffer += len; - total -= len; - } - - return size; -} - int32_t proxy_link_send(int32_t sd, struct iovec *iov, int32_t count) { struct iovec iov_copy[count]; diff --git a/src/libcephfs_proxy/proxy_link.h b/src/libcephfs_proxy/proxy_link.h index 01a32d943778..163e74121219 100644 --- a/src/libcephfs_proxy/proxy_link.h +++ b/src/libcephfs_proxy/proxy_link.h @@ -40,12 +40,6 @@ void proxy_link_close(proxy_link_t *link); int32_t proxy_link_server(proxy_link_t *link, const char *path, proxy_link_start_t start, proxy_link_stop_t stop); -int32_t proxy_link_read(proxy_link_t *link, int32_t sd, void *buffer, - int32_t size); - -int32_t proxy_link_write(proxy_link_t *link, int32_t sd, void *buffer, - int32_t size); - int32_t proxy_link_send(int32_t sd, struct iovec *iov, int32_t count); int32_t proxy_link_recv(int32_t sd, struct iovec *iov, int32_t count);