s3: VFS: vfs_snapper: Make chflags return errno = EROFS on a shadow copy path.
[Samba.git] / ctdb / server / ctdb_tunnel.c
blob2df94746ed485464b478d25707e3c1282e4676c7
1 /*
2 ctdb_tunnel protocol code
4 Copyright (C) Amitay Isaacs 2017
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, see <http://www.gnu.org/licenses/>.
20 #include "replace.h"
21 #include "system/network.h"
23 #include <talloc.h>
24 #include <tevent.h>
25 #include <tdb.h>
27 #include "lib/util/debug.h"
29 #include "common/logging.h"
30 #include "common/reqid.h"
31 #include "common/srvid.h"
33 #include "ctdb_private.h"
35 int32_t ctdb_control_tunnel_register(struct ctdb_context *ctdb,
36 uint32_t client_id, uint64_t tunnel_id)
38 struct ctdb_client *client;
39 int ret;
41 client = reqid_find(ctdb->idr, client_id, struct ctdb_client);
42 if (client == NULL) {
43 DEBUG(DEBUG_ERR, ("Bad client_id in ctdb_tunnel_register\n"));
44 return -1;
47 ret = srvid_exists(ctdb->tunnels, tunnel_id, NULL);
48 if (ret == 0) {
49 DEBUG(DEBUG_ERR,
50 ("Tunnel id 0x%"PRIx64" already registered\n",
51 tunnel_id));
52 return -1;
55 ret = srvid_register(ctdb->tunnels, client, tunnel_id,
56 daemon_tunnel_handler, client);
57 if (ret != 0) {
58 DEBUG(DEBUG_ERR,
59 ("Failed to register tunnel id 0x%"PRIx64"\n",
60 tunnel_id));
61 return -1;
64 DEBUG(DEBUG_INFO, ("Registered tunnel for id 0x%"PRIx64"\n",
65 tunnel_id));
66 return 0;
69 int32_t ctdb_control_tunnel_deregister(struct ctdb_context *ctdb,
70 uint32_t client_id, uint64_t tunnel_id)
72 struct ctdb_client *client;
73 int ret;
75 client = reqid_find(ctdb->idr, client_id, struct ctdb_client);
76 if (client == NULL) {
77 DEBUG(DEBUG_ERR, ("Bad client_id in ctdb_tunnel_deregister\n"));
78 return -1;
81 ret = srvid_deregister(ctdb->tunnels, tunnel_id, client);
82 if (ret != 0) {
83 DEBUG(DEBUG_ERR,
84 ("Failed to deregister tunnel id 0x%"PRIx64"\n",
85 tunnel_id));
86 return -1;
89 return 0;
92 int ctdb_daemon_send_tunnel(struct ctdb_context *ctdb, uint32_t destnode,
93 uint64_t tunnel_id, uint32_t flags, TDB_DATA data)
95 struct ctdb_req_tunnel_old *c;
96 size_t len;
98 if (ctdb->methods == NULL) {
99 DEBUG(DEBUG_INFO,
100 ("Failed to send tunnel. Transport is DOWN\n"));
101 return -1;
104 len = offsetof(struct ctdb_req_tunnel_old, data) + data.dsize;
105 c = ctdb_transport_allocate(ctdb, ctdb, CTDB_REQ_TUNNEL, len,
106 struct ctdb_req_tunnel_old);
107 if (c == NULL) {
108 DEBUG(DEBUG_ERR,
109 ("Memory error in ctdb_daemon_send_tunnel()\n"));
110 return -1;
113 c->hdr.destnode = destnode;
114 c->tunnel_id = tunnel_id;
115 c->flags = flags;
116 c->datalen = data.dsize;
117 memcpy(c->data, data.dptr, data.dsize);
119 ctdb_queue_packet(ctdb, &c->hdr);
121 talloc_free(c);
122 return 0;
125 void ctdb_request_tunnel(struct ctdb_context *ctdb,
126 struct ctdb_req_header *hdr)
128 struct ctdb_req_tunnel_old *c =
129 (struct ctdb_req_tunnel_old *)hdr;
130 TDB_DATA data;
131 int ret;
133 data.dsize = hdr->length;
134 data.dptr = (uint8_t *)c;
136 ret = srvid_dispatch(ctdb->tunnels, c->tunnel_id, 0, data);
137 if (ret != 0) {
138 DEBUG(DEBUG_ERR, ("Tunnel id 0x%"PRIx64" not registered\n",
139 c->tunnel_id));