]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
libcephfs_proxy: replace legacy handshake by negotation in client side
authorXavi Hernandez <xhernandez@gmail.com>
Tue, 11 Feb 2025 17:03:00 +0000 (18:03 +0100)
committerXavi Hernandez <xhernandez@gmail.com>
Fri, 14 Feb 2025 15:15:00 +0000 (16:15 +0100)
Make client code to actually use the new negotiation functions during
connection establishment.

Signed-off-by: Xavi Hernandez <xhernandez@gmail.com>
src/libcephfs_proxy/libcephfs_proxy.c
src/libcephfs_proxy/proxy.h
src/libcephfs_proxy/proxy_link.h

index eca7e7bbbcbf38913a238407bcb362fc652f32a0..719c87895ff6c8c47aa6d4768c930d30d78fcfc1 100644 (file)
  * 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);
index 6f2fec8a59b9993186ee1b6d764610ad012fd0dc..89033d4d548e60b9b8623d54f59632a48ed534c7 100644 (file)
 #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;
 
index 1d89e8a5055253f8f85b031f3e3566ffc72b503d..e4513b001309a2a0aaacea8680a3036c4c1651a3 100644 (file)
@@ -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;