Net-LibNFS
view release on metacpan or search on metacpan
libnfs/examples/nfs4-cat-talloc.c view on Meta::CPAN
if (events & POLLIN) {
flags |= TEVENT_FD_READ;
}
if (events & POLLOUT) {
flags |= TEVENT_FD_WRITE;
}
tevent_fd_set_flags(fde, flags);
}
struct server {
struct rpc_context *rpc;
struct tevent_fd *fde;
};
/*
* Helper functions to send client RPC requests.
*/
static void send_setclientid(struct rpc_context *rpc,
rpc_cb cb, void *private_data)
{
struct client *client = private_data;
COMPOUND4args args;
SETCLIENTID4args *sc4args;
nfs_argop4 op[1];
struct sockaddr_storage ss;
socklen_t len = sizeof(ss);
struct sockaddr_in *in;
struct sockaddr_in6 *in6;
char *netid;
char str[240], addr[256];
unsigned short port;
if (getsockname(client->callback_fd, (struct sockaddr *)&ss, &len) < 0) {
fprintf(stderr, "getsockaddr failed\n");
talloc_free(client);
exit(10);
}
switch (ss.ss_family) {
case AF_INET:
netid = "tcp";
in = (struct sockaddr_in *)&ss;
inet_ntop(AF_INET, &in->sin_addr, str, sizeof(str));
port = ntohs(in->sin_port);
break;
case AF_INET6:
netid = "tcp6";
in6 = (struct sockaddr_in6 *)&ss;
inet_ntop(AF_INET6, &in6->sin6_addr, str, sizeof(str));
port = ntohs(in6->sin6_port);
break;
}
sprintf(addr, "%s.%d.%d", str, port >> 8, port & 0xff);
memset(op, 0, sizeof(op));
op[0].argop = OP_SETCLIENTID;
sc4args = &op[0].nfs_argop4_u.opsetclientid;
memcpy(sc4args->client.verifier, client->verifier, sizeof(verifier4));
sc4args->client.id.id_len = strlen(client->id);
sc4args->client.id.id_val = client->id;
sc4args->callback.cb_program = NFS4_CALLBACK;
sc4args->callback.cb_location.r_netid = netid;
sc4args->callback.cb_location.r_addr = addr;
sc4args->callback_ident = 0x00000001;
memset(&args, 0, sizeof(args));
args.argarray.argarray_len = sizeof(op) / sizeof(nfs_argop4);
args.argarray.argarray_val = op;
if (rpc_nfs4_compound_async(rpc, cb, &args, private_data) != 0) {
fprintf(stderr, "Failed to send nfs4 SETCLIENTID request\n");
talloc_free(client);
exit(10);
}
}
static void send_setclientid_confirm(struct rpc_context *rpc,
rpc_cb cb, void *private_data)
{
struct client *client = private_data;
COMPOUND4args args;
SETCLIENTID_CONFIRM4args *scc4args;
nfs_argop4 op[1];
memset(op, 0, sizeof(op));
op[0].argop = OP_SETCLIENTID_CONFIRM;
scc4args = &op[0].nfs_argop4_u.opsetclientid_confirm;
scc4args->clientid = client->clientid;
memcpy(scc4args->setclientid_confirm, client->setclientid_confirm,
NFS4_VERIFIER_SIZE);
memset(&args, 0, sizeof(args));
args.argarray.argarray_len = sizeof(op) / sizeof(nfs_argop4);
args.argarray.argarray_val = op;
if (rpc_nfs4_compound_async(rpc, cb, &args, private_data) != 0) {
fprintf(stderr, "Failed to send nfs4 SETCLIENTID_CONFIRM request\n");
talloc_free(client);
exit(10);
}
}
static void send_getrootfh(struct rpc_context *rpc,
rpc_cb cb, void *private_data)
{
struct client *client = private_data;
COMPOUND4args args;
nfs_argop4 op[2];
memset(op, 0, sizeof(op));
op[0].argop = OP_PUTROOTFH;
op[1].argop = OP_GETFH;
memset(&args, 0, sizeof(args));
args.argarray.argarray_len = sizeof(op) / sizeof(nfs_argop4);
args.argarray.argarray_val = op;
if (rpc_nfs4_compound_async(rpc, cb, &args, private_data) != 0) {
fprintf(stderr, "Failed to send nfs4 GETROOTFH request\n");
talloc_free(client);
exit(10);
}
}
static void send_open(struct rpc_context *rpc, nfs_fh4 dir, char *path,
rpc_cb cb, void *private_data)
{
struct client *client = private_data;
COMPOUND4args args;
ACCESS4args *a4args;
LOOKUP4args *l4args;
OPEN4args *o4args;
nfs_argop4 *op;
int i = 0, idx = 0;
char *tmp;
/*
* Count how many directories we have in the path.
*/
tmp = path;
while (tmp = strchr(tmp, '/')) {
i++;
tmp++;
}
op = talloc_zero_array(client, nfs_argop4, 4 + i);
op[idx].argop = OP_PUTFH;
libnfs/examples/nfs4-cat-talloc.c view on Meta::CPAN
exit(10);
}
if (res->status != NFS4_OK) {
fprintf(stderr, "Failed to get root filehandle of server %s\n",
client->server);
talloc_free(client);
exit(10);
}
gfh4res = &res->resarray.resarray_val[1].nfs_resop4_u.opgetfh;
send_open(rpc, gfh4res->GETFH4res_u.resok4.object,
client->path, open_cb, client);
}
void setclientid_confirm_cb(struct rpc_context *rpc, int status, void *data,
void *private_data)
{
struct client *client = private_data;
COMPOUND4res *res = data;
char *path;
if (status != RPC_STATUS_SUCCESS) {
fprintf(stderr, "Failed to set client id of server %s\n",
client->server);
talloc_free(client);
exit(10);
}
if (res->status != NFS4_OK) {
fprintf(stderr, "Failed to set client id of server %s\n",
client->server);
talloc_free(client);
exit(10);
}
send_getrootfh(rpc, getrootfh_cb, client);
}
void setclientid_cb(struct rpc_context *rpc, int status, void *data,
void *private_data)
{
struct client *client = private_data;
COMPOUND4res *res = data;
SETCLIENTID4res *sc4res;
if (status != RPC_STATUS_SUCCESS) {
fprintf(stderr, "Failed to set client id on server %s\n",
client->server);
talloc_free(client);
exit(10);
}
if (res->status != NFS4_OK) {
fprintf(stderr, "Failed to set client id on server %s\n",
client->server);
talloc_free(client);
exit(10);
}
sc4res = &res->resarray.resarray_val[0].nfs_resop4_u.opsetclientid;
client->clientid = sc4res->SETCLIENTID4res_u.resok4.clientid;
memcpy(client->setclientid_confirm,
sc4res->SETCLIENTID4res_u.resok4.setclientid_confirm,
NFS4_VERIFIER_SIZE);
send_setclientid_confirm(rpc, setclientid_confirm_cb, client);
}
/*
* NULL procedure for the callback protocol.
*/
static int cb_null_proc(struct rpc_context *rpc, struct rpc_msg *call, void *opaque)
{
rpc_send_reply(rpc, call, NULL, (zdrproc_t)zdr_void, 0);
return 0;
}
/*
* CB_COMPOUND procedure for the callback protocol.
* This is where the server will inform us about lease breaks and similar.
*/
static int cb_compound_proc(struct rpc_context *rpc, struct rpc_msg *call, void *opaque)
{
CB_COMPOUND4args *args = call->body.cbody.args;
fprintf(stderr, "cb_compund_cb. Do something here.\n");
return 0;
}
struct service_proc pt[] = {
{CB_NULL, cb_null_proc,
(zdrproc_t)zdr_void, 0},
{CB_COMPOUND, cb_compound_proc,
(zdrproc_t)zdr_CB_COMPOUND4args, sizeof(CB_COMPOUND4args)},
};
static void server_io(struct tevent_context *ev, struct tevent_fd *fde,
uint16_t events, void *private_data)
{
struct server *server = private_data;
int revents = 0;
if (events & TEVENT_FD_READ) {
revents |= POLLIN;
}
if (events & TEVENT_FD_WRITE) {
revents |= POLLOUT;
}
if (rpc_service(server->rpc, revents) < 0) {
talloc_free(server);
return;
}
update_events(server->rpc, server->fde);
}
static int server_destructor(struct server *s)
{
( run in 0.904 second using v1.01-cache-2.11-cpan-71847e10f99 )