From: Xavi Hernandez Date: Tue, 11 Feb 2025 17:03:00 +0000 (+0100) Subject: libcephfs_proxy: replace legacy handshake by negotation in client side X-Git-Tag: v20.3.0~362^2~11 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=4714e40d702917378255c8c9bc0de5fd36e43a36;p=ceph.git libcephfs_proxy: replace legacy handshake by negotation in client side Make client code to actually use the new negotiation functions during connection establishment. Signed-off-by: Xavi Hernandez --- diff --git a/src/libcephfs_proxy/libcephfs_proxy.c b/src/libcephfs_proxy/libcephfs_proxy.c index eca7e7bbbcbf..719c87895ff6 100644 --- a/src/libcephfs_proxy/libcephfs_proxy.c +++ b/src/libcephfs_proxy/libcephfs_proxy.c @@ -12,23 +12,34 @@ * so this won't be noticed. */ struct ceph_mount_info { proxy_link_t link; + proxy_link_negotiate_t neg; uint64_t cmount; }; /* The global_cmount is used to stablish an initial connection to serve requests * not related to a real cmount, like ceph_version or ceph_userperm_new. */ -static struct ceph_mount_info global_cmount = { PROXY_LINK_DISCONNECTED, 0 }; +static struct ceph_mount_info global_cmount = { + .link = PROXY_LINK_DISCONNECTED, + .neg = {}, + .cmount = 0 +}; static bool client_stop(proxy_link_t *link) { return false; } +static int32_t proxy_negotiation_check(proxy_link_negotiate_t *neg) +{ + proxy_log(LOG_INFO, 0, "Features enabled: %08x", neg->v1.enabled); + + return 0; +} + static int32_t proxy_connect(proxy_link_t *link) { - CEPH_REQ(hello, req, 0, ans, 0); char *path, *env; - int32_t sd, err; + int32_t sd; path = PROXY_SOCKET; env = getenv(PROXY_SOCKET_ENV); @@ -41,31 +52,7 @@ static int32_t proxy_connect(proxy_link_t *link) return sd; } - req.id = LIBCEPHFS_LIB_CLIENT; - err = proxy_link_send(sd, req_iov, 1); - if (err < 0) { - goto failed; - } - err = proxy_link_recv(sd, ans_iov, 1); - if (err < 0) { - goto failed; - } - - proxy_log(LOG_INFO, 0, "Connected to libcephfsd version %d.%d", - ans.major, ans.minor); - - if ((ans.major != LIBCEPHFSD_MAJOR) || - (ans.minor != LIBCEPHFSD_MINOR)) { - err = proxy_log(LOG_ERR, ENOTSUP, "Version not supported"); - goto failed; - } - return sd; - -failed: - proxy_link_close(link); - - return err; } static void proxy_disconnect(proxy_link_t *link) @@ -81,6 +68,19 @@ static int32_t proxy_global_connect(void) if (!proxy_link_is_connected(&global_cmount.link)) { err = proxy_connect(&global_cmount.link); + if (err < 0) { + return err; + } + + proxy_link_negotiate_init(&global_cmount.neg, 0, PROXY_FEAT_ALL, + 0, 0); + + err = proxy_link_handshake_client(&global_cmount.link, err, + &global_cmount.neg, + proxy_negotiation_check); + if (err < 0) { + proxy_disconnect(&global_cmount.link); + } } return err; @@ -178,6 +178,16 @@ __public int ceph_create(struct ceph_mount_info **cmount, const char *const id) } sd = err; + proxy_link_negotiate_init(&ceph_mount->neg, 0, PROXY_FEAT_ALL, 0, 0); + + err = proxy_link_handshake_client(&ceph_mount->link, sd, + &ceph_mount->neg, + proxy_negotiation_check); + if (err < 0) { + goto failed_link; + } + + CEPH_STR_ADD(req, id, id); err = CEPH_CALL(sd, LIBCEPHFSD_OP_CREATE, req, ans); diff --git a/src/libcephfs_proxy/proxy.h b/src/libcephfs_proxy/proxy.h index 6f2fec8a59b9..89033d4d548e 100644 --- a/src/libcephfs_proxy/proxy.h +++ b/src/libcephfs_proxy/proxy.h @@ -25,6 +25,11 @@ #define container_of(_ptr, _type, _field) \ ((_type *)((uintptr_t)(_ptr) - offset_of(_type, _field))) +enum { + /* Mask of all supported/known features. */ + PROXY_FEAT_ALL = 0x00000000 +}; + struct _list; typedef struct _list list_t; diff --git a/src/libcephfs_proxy/proxy_link.h b/src/libcephfs_proxy/proxy_link.h index 1d89e8a50552..e4513b001309 100644 --- a/src/libcephfs_proxy/proxy_link.h +++ b/src/libcephfs_proxy/proxy_link.h @@ -72,6 +72,28 @@ typedef struct _proxy_link_ans { sizeof(proxy_link_negotiate_v##_ver##_t)) #define NEG_VERSION_SIZE(_ver) NEG_VERSION_SIZE_1(_ver) +#define proxy_link_negotiate_init_v0(_neg, _ver, _min) \ + do { \ + (_neg)->v0.size = NEG_VERSION_SIZE(_ver); \ + (_neg)->v0.version = (_ver); \ + (_neg)->v0.min_version = (_min); \ + (_neg)->v0.flags = 0; \ + } while (0) + +/* NEG_VERSION: Add new arguments and initialize the link->neg.vX with them. */ +static inline void proxy_link_negotiate_init(proxy_link_negotiate_t *neg, + uint32_t min_version, + uint32_t supported, + uint32_t required, + uint32_t enabled) +{ + proxy_link_negotiate_init_v0(neg, PROXY_LINK_NEGOTIATE_VERSION, + min_version); + neg->v1.supported = supported; + neg->v1.required = required; + neg->v1.enabled = enabled; +} + static inline bool proxy_link_is_connected(proxy_link_t *link) { return link->sd >= 0;