2 * 2011+ Copyright (c) Evgeniy Polyakov <zbr@ioremap.net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
18 #include <sys/types.h>
20 #include <sys/socket.h>
31 #include "elliptics.h"
33 #include <elliptics/packet.h>
34 #include <elliptics/interface.h>
36 #include <elliptics/srw/srwc.h>
38 int dnet_srw_init(struct dnet_node
*n
, struct dnet_config
*cfg
)
43 cfg
->srw
.config
= cfg
->addr
;
45 dnet_log(n
, DNET_LOG_INFO
, "srw: binary: '%s', log: '%s', pipe: '%s', init: '%s', config: '%s', threads: %d\n",
46 cfg
->srw
.binary
, cfg
->srw
.log
, cfg
->srw
.pipe
, cfg
->srw
.init
, cfg
->srw
.config
, cfg
->srw
.num
);
48 if (!cfg
->srw
.init
|| cfg
->srw
.num
<= 0 || !cfg
->srw
.binary
|| !cfg
->srw
.pipe
) {
50 dnet_log(n
, DNET_LOG_INFO
, "srw: do not initialize - insufficient parameters in config\n");
56 n
->srw
= srwc_init(&cfg
->srw
);
59 dnet_log(n
, DNET_LOG_ERROR
, "srw: failed to initialize external python workers\n");
67 void dnet_srw_cleanup(struct dnet_node
*n
)
73 int dnet_cmd_exec_raw(struct dnet_net_state
*st
, struct dnet_cmd
*cmd
, struct dnet_attr
*attr
,
74 struct sph
*header
, const void *data
)
76 struct dnet_node
*n
= st
->n
;
80 memset(&ctl
, 0, sizeof(struct srwc_ctl
));
84 err
= srwc_process(n
->srw
, &ctl
, data
);
86 dnet_log(n
, DNET_LOG_ERROR
, "%s: python processing failed: %s %d\n", dnet_dump_id(&cmd
->id
), strerror(-err
), err
);
90 dnet_log(n
, DNET_LOG_DSA
, "%s: reply %llu bytes: '%.*s'\n",
91 dnet_dump_id(&cmd
->id
), (unsigned long long)ctl
.res_size
, (int)ctl
.res_size
, ctl
.result
);
94 err
= dnet_send_reply(st
, cmd
, attr
, ctl
.result
, ctl
.res_size
, 0);
102 int dnet_srw_update(struct dnet_node
*n
, int pid
)
104 return srwc_drop(n
->srw
, pid
);