PadicoTM

Documentation

« back to PM2 home.
tube_gk-mod.c
Go to the documentation of this file.
1/*
2 * Padico -- a High Performance Parallel and Distributed Computing Environment
3 * Copyright (c) 2002-2025 INRIA and the University of Rennes 1
4 * Alexandre DENIS <Alexandre.Denis@inria.fr>
5 * Christian PEREZ <Christian.Perez@inria.fr>
6 *
7 * The software has been registered at the Agency for the Protection of
8 * Programs (APP) under the number IDDN.FR.001.260013.000.S.P.2002.000.10000.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
24
34#include <Padico/Puk.h>
35#include <Padico/PadicoTM.h>
36#include <Padico/PM2.h>
37#include <Padico/Topology.h>
38#include <Padico/Module.h>
39#include <errno.h>
40
41#include "padico-run_tube.h"
42
43static int tube_gk_init(void);
44static void tube_gk_stop(void);
45
46static int sockfd = 0;
48
50
51
52/* ******************************************* */
53
54static int write_tube(int fd, void*data, size_t size)
55{
56 padico_out(30,"** WRITE (%i)**\n", size);
58 if( ret < size)
59 padico_fatal("Write error: %s\n", strerror(__puk_abi_wrap__errno));
60 return ret;
61}
62
63static void write_char_tube(int fd, const char*string)
64{
65 if(string != NULL)
66 {
67 int len = strlen(string)+1;
68 int ret = 0;
69 ret += write_tube(fd, &len, sizeof(int));
70 if( ret < 0)
71 padico_fatal("Write error: %s\n", strerror(__puk_abi_wrap__errno));
72 ret += write_tube(fd, (void*)string, len);
73 if( ret < 0)
74 padico_fatal("Write error: %s\n", strerror(__puk_abi_wrap__errno));
75 } else {
76 int len = 0;
77 write_tube(fd, &len, sizeof(int));
78 }
79}
80
81static int read_tube(int fd, void*data, size_t size)
82{
83 padico_out(30, "** READ (%i) **\n", size);
85 if(ret < size)
86 padico_fatal("Read error: %s\n", strerror(__puk_abi_wrap__errno));
87 return ret;
88}
89
90static void read_char_tube(int fd, char**ptr)
91{
92 int size = 0;
93 int ret = read_tube(fd, &size, sizeof(int));
94 if(size > 0)
95 {
96 char * tmp = padico_malloc(size*sizeof(char));
97 read_tube(fd, tmp, size*sizeof(char));
98 *ptr = tmp;
99 }
100 if(ret < 0)
101 padico_fatal("Read char error: %s\n", strerror(__puk_abi_wrap__errno));
102}
103
104static void send_rc(int fd, padico_rc_t rc)
105{
106 if(rc != NULL)
107 {
108 write_tube(fd, &(rc->rc), sizeof(int));
109 write_char_tube(fd, (const char*)rc->msg);
110 } else {
111 int rc = 0;
112 char*msg = NULL;
113 write_tube(fd, &rc, sizeof(int));
114 write_char_tube(fd, (const char*)msg);
115 }
116}
117
118static int answer_cmd(int cmd, int fd)
119{
120 padico_out(30,"** Callback call on fd %i: %i **\n", fd, cmd);
121 if(fd > 0)
122 {
123 switch(cmd){
124 int i = 0, ret = 0, size = 0, argc = 0;
126 char*modID = NULL, **argv = NULL, *tmp = NULL, *groupID = NULL,
130 struct puk_parse_entity_s pe;
131 case TUBE_PING:
132 ret = 1;
133 write_tube(fd, &ret, sizeof(int));
134 break;
135 case TUBE_KILL:
136 ret = 1;
137 write_tube(fd, &ret, sizeof(int));
139 break;
140 case TUBE_LISTMODULES:
143 write_tube(fd, &size, sizeof(int));
144 for(i=0;i<size;i++)
146 break;
147 case TUBE_LOADMODULE:
148 read_char_tube(fd, &modID);
150 send_rc(fd, rc);
151 break;
152 case TUBE_RUNMODULE:
153 read_char_tube(fd, &modID);
154 read_tube(fd, &argc, sizeof(int));
155 argv = padico_malloc(argc*sizeof(char*));
156 for(i=0;i<argc;i++)
157 {
158 tmp = (*argv)+i;
160 }
161 rc = padico_tm_mod_action_args(PADICO_TM_MOD_RUN, modID, argc, argv);
162 send_rc(fd, rc);
163 break;
165 read_char_tube(fd, &modID);
167 send_rc(fd, rc);
168 break;
169 case TUBE_CREATEGROUP:
170 read_char_tube(fd, &groupID);
171 if(padico_group_lookup(groupID) != NULL)
172 {
173 rc = padico_rc_error("cannot create group: groupID=**%s** already exists.", groupID);
174 padico_print("Error creating group: it already exists\n");
175 }
176 else
177 {
178 group = padico_group_init(groupID);
179 read_tube(fd, &size, sizeof(int));
180 for(i=0;i<size;i++)
181 {
184 if(node != NULL)
185 {
187 }
188 else
189 {
190 rc = padico_rc_error("cannot add node **%s**: not recognized as a valid nodeID.", nodeID);
191 break;
192 }
193 }
194 }
196 {
198 padico_print("Group created: %s\n", groupID);
199 }
200 send_rc(fd, rc);
201 break;
205 padico_rc_show(pe.rc);
206 send_rc(fd, pe.rc);
207 break;
208 default:
209 padico_warning("Tube Command not understood: %i\n", cmd);
210 break;
211 }
212 }
213 return 0;
214}
215
216static int tube_callback(int fd, void*key)
217{
218 int cmd = 0;
219 int newsockfd = 0;
221 if(newsockfd < 0)
222 padico_fatal("Accept error: %s", strerror(__puk_abi_wrap__errno));
223 read_tube(newsockfd, &cmd, sizeof(int));
224 answer_cmd(cmd, newsockfd);
225 close(newsockfd);
226 return 1;
227}
228
229static int tube_gk_init(void)
230{
231 const int LISTENQ = 10;
232
233 /* Prepare communication */
234 struct sockaddr_un addr;
239 memset(&addr, 0, sizeof(struct sockaddr_un));
240 addr.sun_family = AF_UNIX;
242 padico_string_catf(str_sk, "%s%s%s", "/tmp/padico/", text, ".sk");
243 strcpy(addr.sun_path, padico_string_get(str_sk));
244
245 /* Prepare /tmp/padico directory */
246 mkdir("/tmp/padico/", S_IRWXU | S_IRWXG | S_IRWXO);
247
248 /* Prepare communications files */
250 if (sockfd < 0)
251 padico_fatal("Socket creation error: %s", strerror(__puk_abi_wrap__errno));
252
253 /* Bind */
254 if(PUK_ABI_FSYS_WRAP(bind)(sockfd, (struct sockaddr *) &addr,
255 sizeof(addr)) < 0)
256 padico_fatal("Bind error: socket:%i, path:%s, error:%s\n",
257 sockfd, addr.sun_path, strerror(__puk_abi_wrap__errno));
258 /* Starting listening */
259 if(PUK_ABI_FSYS_WRAP(listen)(sockfd, LISTENQ) < 0)
260 padico_fatal("Listen error: %s.\n", strerror(__puk_abi_wrap__errno));
261
265 return 0;
266}
267
268static void tube_gk_stop(void)
269{
270 /* Closing the server */
272 close(sockfd);
273}
const const struct ns_rule_bucket_s * key
return NULL
Definition Shm.h:88
static padico_group_t group
static int done
Definition console-mod.c:49
static int size
Definition datacheck.c:34
static int fd
Definition datacheck.c:32
void padico_tm_exit(void)
padico_rc_t padico_tm_mod_action_args(enum padico_mtask_kind_e kind, const char *mod_name, int argc, char **argv)
Definition tm-mod.c:46
#define PUK_ABI_FSYS_WRAP(SYM)
Definition PadicoTM.h:88
padico_rc_t rc
Definition PadicoTM.h:146
#define __puk_abi_wrap__errno
Definition PadicoTM.h:101
static padico_rc_t padico_tm_mod_action(enum padico_mtask_kind_e kind, const char *mod_name)
Definition PadicoTM.h:254
@ PADICO_TM_MOD_LOAD
Definition PadicoTM.h:200
@ PADICO_TM_MOD_RUN
Definition PadicoTM.h:202
@ PADICO_TM_MOD_UNLOAD
Definition PadicoTM.h:201
#define PADICO_IO_EVENT_READ
the fildes is readable
Definition SysIO.h:62
ssize_t padico_sysio_in(int fildes, void *buf, size_t nbyte)
Definition sysio.c:792
void padico_io_activate(padico_sysio_t io)
Activates the I/O handle - when not activated, the callback is not triggered.
Definition sysio.c:278
padico_sysio_t padico_io_register(int fd, unsigned int what, padico_sysio_callback_t callback, void *key)
Registers a file descriptor for polling.
Definition sysio.c:205
#define padico_io_t
for backwards compatibility with legacy codes
Definition SysIO.h:53
void padico_io_deactivate(padico_sysio_t io)
Deactivate the I/O handle - should be used for temporarly deactivate callback trigger.
Definition sysio.c:288
ssize_t padico_sysio_out(int fildes, const void *buf, size_t nbyte)
Definition sysio.c:808
padico_topo_node_t padico_topo_getlocalnode(void)
Definition topology.c:1891
padico_topo_uuid_t padico_topo_node_getuuid(padico_topo_node_t node)
Get the UUID of a node.
Definition topology.c:1912
padico_topo_node_t padico_topo_getnodebyname(const char *nodename)
node lookup, by node name
Definition topology.c:2389
padico_topo_node_t node
Definition na-control.c:65
padico_group_t padico_group_init(const char *id)
Definition na-group.c:208
void padico_group_publish(padico_group_t group)
Publishes a group to its members.
Definition na-group.c:295
void padico_group_node_add(padico_group_t g, padico_topo_node_t node)
Definition na-group.c:233
padico_group_t padico_group_lookup(const char *id)
Definition na-group.c:225
tube back-end for padico-run
#define TUBE_UNLOADMODULE
#define TUBE_RUNMODULE
#define TUBE_KILL
#define TUBE_LOADMODULE
#define TUBE_PING
#define TUBE_CREATEGROUP
#define TUBE_LISTMODULES
#define TUBE_RAWXMLCOMMAND
a group of nodes
Definition na-group.c:43
void * data
place-holder for actual data
static void write_char_tube(int fd, const char *string)
Definition tube_gk-mod.c:63
static int answer_cmd(int cmd, int fd)
static int write_tube(int fd, void *data, size_t size)
Definition tube_gk-mod.c:54
static void read_char_tube(int fd, char **ptr)
Definition tube_gk-mod.c:90
static void tube_gk_stop(void)
static void send_rc(int fd, padico_rc_t rc)
static int sockfd
Definition tube_gk-mod.c:46
static int tube_callback(int fd, void *key)
static int tube_gk_init(void)
static int read_tube(int fd, void *data, size_t size)
Definition tube_gk-mod.c:81
static padico_io_t in_io
Definition tube_gk-mod.c:47
char * ptr
Definition vpipe.c:83