Skip to content

Commit

Permalink
Fix version negotiations with user socket (openzfs#412)
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Dagnelie <[email protected]>
  • Loading branch information
pcd1193182 authored May 7, 2022
1 parent 7f5c4dc commit fb75cf5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 23 deletions.
2 changes: 1 addition & 1 deletion cmd/zfs_object_agent/zcache/src/remote_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl RemoteChannel {
async fn agent_version(stream: &mut UnixStream) -> Result<Version> {
let mut vers_req_nvlist = NvList::new_unique_names();
vers_req_nvlist.insert(AGENT_REQUEST_TYPE, TYPE_VERSION)?;
vers_req_nvlist.insert("version", "^1")?;
vers_req_nvlist.insert("version", ">=1.0.0, < 3.0.0")?;
Self::send(stream, vers_req_nvlist).await?;
let response = Self::receive(stream).await?;
assert!(response.lookup_string(AGENT_RESPONSE_TYPE)?.to_str() == Ok(TYPE_VERSION));
Expand Down
17 changes: 5 additions & 12 deletions lib/libzutil/zutil_import.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,6 @@
#include "zutil_import.h"
#include "zutil_zoa.h"

/*
* This specifies that this code supports all 1.X.Y versions of the agent
* communication protocol. This should be updated as new capabilities are
* added and supported or required.
*/
#define AGENT_PROTOCOL_VERSION "^1"

__attribute__((format(printf, 2, 3))) void
zutil_error_aux(libpc_handle_t *hdl, const char *fmt, ...)
{
Expand Down Expand Up @@ -1843,7 +1836,7 @@ zpool_find_import_cached(libpc_handle_t *hdl, importargs_t *iarg)
* to prevent the import from hanging.
*/
int sock = zoa_connect_agent(hdl, ZFS_ROOT_SOCKET,
AGENT_PROTOCOL_VERSION, NULL);
AGENT_PUBLIC_PROTOCOL_VERSION, NULL);
if (sock == -1) {
continue;
}
Expand Down Expand Up @@ -1905,8 +1898,8 @@ zpool_find_import_agent(libpc_handle_t *hdl, importargs_t *iarg,
if (iarg->guid != 0)
fnvlist_add_uint64(msg, AGENT_GUID, iarg->guid);

nvlist_t *resp = zoa_send_recv_msg(hdl, msg, AGENT_PROTOCOL_VERSION,
ZFS_PUBLIC_SOCKET, NULL);
nvlist_t *resp = zoa_send_recv_msg(hdl, msg,
AGENT_PUBLIC_PROTOCOL_VERSION, ZFS_PUBLIC_SOCKET, NULL);

nvpair_t *elem = NULL;
while ((elem = nvlist_next_nvpair(resp, elem)) != NULL) {
Expand Down Expand Up @@ -2205,8 +2198,8 @@ zoa_resume_destroy(void *hdl, importargs_t *iarg)
fnvlist_add_string(msg, AGENT_NAME, iarg->poolname);
}

nvlist_t *resp = zoa_send_recv_msg(&handle, msg, AGENT_PROTOCOL_VERSION,
ZFS_ROOT_SOCKET, NULL);
nvlist_t *resp = zoa_send_recv_msg(&handle, msg,
AGENT_PUBLIC_PROTOCOL_VERSION, ZFS_ROOT_SOCKET, NULL);
if (resp == NULL)
return (-1);

Expand Down
13 changes: 3 additions & 10 deletions lib/libzutil/zutil_zoa.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,6 @@
*/
#define ZOA_MAX_RETRIES 15

/*
* This specifies that this code supports all 1.X.Y versions of the agent
* communication protocol. This should be updated as new capabilities are
* added and supported or required.
*/
#define AGENT_PROTOCOL_VERSION ">=1.0.0, <3.0.0"

struct sockaddr_un zfs_public_socket = {
AF_UNIX, "/etc/zfs/zfs_public_socket"
};
Expand Down Expand Up @@ -330,8 +323,8 @@ zoa_list_destroy_pools(libpc_handle_t *hdl, boolean_t destroy_complete)
fnvlist_add_string(msg, AGENT_REQUEST_TYPE,
AGENT_TYPE_GET_DESTROYING_POOLS);

nvlist_t *resp = zoa_send_recv_msg(hdl, msg, AGENT_PROTOCOL_VERSION,
ZFS_PUBLIC_SOCKET, &version);
nvlist_t *resp = zoa_send_recv_msg(hdl, msg,
AGENT_PUBLIC_PROTOCOL_VERSION, ZFS_PUBLIC_SOCKET, &version);
if (resp == NULL) {
if (version != NULL)
fnvlist_free(version);
Expand Down Expand Up @@ -434,7 +427,7 @@ zoa_clear_destroyed_pools(void *hdl)
fnvlist_add_string(msg, AGENT_REQUEST_TYPE,
AGENT_TYPE_CLEAR_DESTROYED_POOLS);

zoa_send_recv_msg(&handle, msg, AGENT_PROTOCOL_VERSION,
zoa_send_recv_msg(&handle, msg, AGENT_PUBLIC_PROTOCOL_VERSION,
ZFS_PUBLIC_SOCKET, NULL);
}

Expand Down
7 changes: 7 additions & 0 deletions lib/libzutil/zutil_zoa.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
#ifndef _LIBZUTIL_ZUTIL_ZOA_H_
#define _LIBZUTIL_ZUTIL_ZOA_H_

/*
* This specifies that this code supports all 1.X.Y and 2.X.Y versions of the
* agent communication protocol. This should be updated as new capabilities
* are added and supported or required.
*/
#define AGENT_PUBLIC_PROTOCOL_VERSION ">=1.0.0, <3.0.0"

typedef enum zoa_socket {
ZFS_PUBLIC_SOCKET,
ZFS_ROOT_SOCKET,
Expand Down

0 comments on commit fb75cf5

Please sign in to comment.