vmod/vmodttl: fixed bug related to luns not ordered and/or not starting from zero.
[ht-drivers.git] / xmem / lib / diag / XmemCmds.c
blob06f747323ece0aa79457215ec40e2f105bb34755
1 #include <sys/types.h>
2 #include <sys/stat.h>
3 #include <sys/ioctl.h>
4 #include <sys/file.h>
5 #include <sys/ipc.h>
6 #include <sys/shm.h>
7 #include <fcntl.h>
8 #include <stdio.h>
9 #include <string.h>
10 #include <ctype.h>
11 #include <time.h>
13 #include <errno.h>
14 extern int errno;
16 #include "../daemon/XmemDaemon.h"
18 static XmemNodeId all_nodes = 0;
19 static XmemTableId all_tables = 0;
21 static XmemTableId ctid = XmemTableId_01;
23 static int timeout = 1000; /* 10 Seconds */
25 static char *ENames[XmemEventMASKS] = {
26 "TimeOut",
27 "SendTable",
28 "Message",
29 "TableUpdate",
30 "Initialized",
31 "IoError",
32 "Kill",
33 "SoftwareError",
34 "SystemError" };
36 static char *IOENames[XmemIoERRORS] = {
37 "Parity",
38 "Rogue",
39 "LostContact",
40 "Hardware",
41 "Software" };
43 static char *InitMess[XmemInitMessageMESSAGES] = {
44 "Acknowledged",
45 "Reset",
46 "UserDefined" };
48 static char *MSNames[XmemMessageTypeCOUNT] = {
49 "SendTable",
50 "Message",
51 "TableUpdated",
52 "Initialize",
53 "Kill" };
55 static XdEventLogEntries *event_log = NULL;
57 /* ========================================================= */
58 /* Callback routins to handle events */
60 void callback(XmemCallbackStruct *cbs) {
62 unsigned long msk, emsk, data;
63 int i, j;
65 printf("Callback:");
66 for (i=0; i<XmemEventMASKS; i++) {
67 msk = 1 << i;
68 if (cbs->Mask & msk) {
69 data = cbs->Data;
70 if ((msk & XmemEventMaskSOFTWARE) && (cbs->Data == XmemErrorSUCCESS)) {
71 printf("Information: ");
72 } else {
73 printf("%s: ",ENames[i]);
75 switch ((XmemEventMask) msk) {
77 case XmemEventMaskTIMEOUT:
78 printf("Timeout\n");
79 break;
81 case XmemEventMaskSEND_TABLE:
82 printf("%s To:%s\n",
83 XmemGetTableName(cbs->Table),
84 XmemGetNodeName(cbs->Node));
85 break;
87 case XmemEventMaskUSER:
88 printf("0x%X (%d) From:%s\n",
89 (int) data,
90 (int) data,
91 XmemGetNodeName(cbs->Node));
92 break;
94 case XmemEventMaskTABLE_UPDATE:
95 printf("%s By:%s\n",
96 XmemGetTableName(cbs->Table),
97 XmemGetNodeName(cbs->Node));
98 break;
100 case XmemEventMaskINITIALIZED:
101 printf("%s Message:0x%X (%d/",
102 XmemGetNodeName(cbs->Node),
103 (int) data,
104 (int) data);
105 if (data < XmemInitMessageMESSAGES)
106 printf("%s)\n",InitMess[data]);
107 else
108 printf("%s)\n",InitMess[XmemInitMessageUSER_DEFINED]);
109 break;
111 case XmemEventMaskIO:
112 case XmemIoERRORS:
113 for (j=0; j<XmemIoERRORS; j++) {
114 emsk = 1 << j;
115 if (emsk & data) printf("%s ",IOENames[j]);
117 printf("\n");
118 break;
120 case XmemEventMaskKILL:
121 printf("\n");
122 break;
124 case XmemEventMaskSYSTEM:
125 printf("%s (%d)\n",
126 strerror((int) data),
127 (int) data);
128 break;
130 case XmemEventMaskSOFTWARE:
131 if (data != XmemErrorSUCCESS) {
132 printf("%s\n",
133 XmemErrorToString((XmemError) data));
135 default: break;
141 /* ========================================================= */
142 /* Convert time to a standard string routine. */
143 /* Result is a pointer to a static string. */
144 /* the format is: Thu-18/Jan/2001 08:25:14 */
145 /* day-dd/mon/yyyy hh:mm:ss */
147 char *TimeToStr(time_t tod) {
149 static char tbuf[128];
151 char tmp[128];
152 char *yr, *ti, *md, *mn, *dy;
154 bzero((void *) tbuf, 128);
155 bzero((void *) tmp, 128);
157 if (tod) {
158 ctime_r(&tod, tmp);
159 tmp[ 3] = 0; dy = &(tmp[0]);
160 tmp[ 7] = 0; mn = &(tmp[4]);
161 tmp[10] = 0; md = &(tmp[8]); if (md[0] == ' ') md[0] = '0';
162 tmp[19] = 0; ti = &(tmp[11]);
163 tmp[24] = 0; yr = &(tmp[20]);
164 sprintf (tbuf, "%s-%s/%s/%s %s" , dy, md, mn, yr, ti);
166 } else sprintf (tbuf, "--- Zero ---");
167 return (tbuf);
170 /* ========================================================= */
171 /* Get the event log table in shared memory */
173 XdEventLogEntries *GetEventLogTable() {
175 key_t smemky;
176 unsigned smemid;
178 static XdEventLogEntries *result = NULL;
180 if (result) return result;
182 smemky = XmemGetKey(EVENT_LOG_NAME);
183 smemid = shmget(smemky,sizeof(XdEventLogEntries),0666);
184 if (smemid == -1) {
185 if (errno == ENOENT) {
186 smemid = shmget(smemky,sizeof(XdEventLogEntries),IPC_CREAT | 0666);
187 if (smemid != -1) {
188 result = (XdEventLogEntries *) shmat(smemid,(char *) 0,0);
189 if ((int) result != -1) {
190 bzero((void *) result, sizeof(XdEventLogEntries));
191 return result;
195 } else {
196 result = (XdEventLogEntries *) shmat(smemid,(char *) 0,0);
197 if ((int) result != -1) return result;
199 XmemErrorCallback(XmemErrorSYSTEM,errno);
200 return NULL;
203 /* ========================================================= */
204 /* Print out a callback structure */
206 char *CallbackToStr(XmemCallbackStruct *cbs) {
208 static char str[128];
210 if (cbs) {
211 bzero((void *) str, 128);
212 switch (cbs->Mask) {
213 case XmemEventMaskTIMEOUT:
214 sprintf(str,"Timeout");
215 break;
217 case XmemEventMaskUSER:
218 sprintf(str,"User event:%d From node:%s",(int) cbs->Data,XmemGetNodeName(cbs->Node));
219 break;
221 case XmemEventMaskSEND_TABLE:
222 sprintf(str,"Send table:%s From node:%s",XmemGetTableName(cbs->Table),XmemGetNodeName(cbs->Node));
223 break;
225 case XmemEventMaskTABLE_UPDATE:
226 sprintf(str,"Update table:%s From node:%s",XmemGetTableName(cbs->Table),XmemGetNodeName(cbs->Node));
227 break;
229 case XmemEventMaskINITIALIZED:
230 sprintf(str,"Initialized:%d From node:%s",(int) cbs->Data,XmemGetNodeName(cbs->Node));
231 break;
233 case XmemEventMaskKILL:
234 sprintf(str,"Kill daemon received");
235 break;
237 case XmemEventMaskIO:
238 sprintf(str,"IO error:%s",XmemErrorToString(cbs->Data));
239 break;
241 case XmemEventMaskSYSTEM:
242 sprintf(str,"System error:%d",(int) cbs->Data);
243 break;
245 case XmemEventMaskSOFTWARE:
246 if (cbs->Data == XmemErrorSUCCESS) {
247 sprintf(str,"Information:");
248 } else {
249 sprintf(str,"Software error:%s",XmemErrorToString(cbs->Data));
251 break;
253 default: break;
255 return str;
257 return NULL;
260 /* ========================================================= */
261 /* Register callback, arg is the event mask */
263 int RegisterCallback(int arg) {
264 ArgVal *v;
265 AtomType at;
266 XmemEventMask emsk;
267 XmemError err;
268 int i;
269 unsigned long msk;
270 arg++;
271 v = &(vals[arg]);
272 at = v->Type;
274 if (at == Operator) {
275 if (v->OId == OprNOOP) {
276 arg++;
277 v = &(vals[arg]);
278 at = v->Type;
280 printf("Possible events are:\n");
282 for (i=0; i<XmemEventMASKS; i++) {
283 msk = 1 << i;
284 printf("Event:0x%03X: %s\n",(int) msk, ENames[i]);
287 return arg;
291 if (at == Numeric) {
292 arg++;
293 emsk = (XmemEventMask) v->Number;
294 } else {
295 emsk = XmemGetRegisteredEvents();
296 if (emsk) {
297 for (i=0; i<XmemEventMASKS; i++) {
298 msk = 1 << i;
299 if (emsk & msk)
300 printf("Registered:0x%03X: %s\n",(int) msk, ENames[i]);
302 } else printf("Registered: No events\n");
303 return arg;
306 err = XmemRegisterCallback(callback,emsk);
307 if (err != XmemErrorSUCCESS)
308 printf("XmemRegisterCallback: Error:%s\n",XmemErrorToString(err));
309 else
310 if (emsk) printf("XmemRegisterCallback: Registered:0x%X OK\n",(int) emsk);
311 else printf("XmemRegisterCallback: Unregistered all OK\n");
312 return arg;
315 /* ========================================================= */
316 /* Call XmemGetAllNodeIds and print list */
318 int GetAllNodeIds(int arg) {
320 int i;
321 unsigned long msk, nid;
323 all_nodes = XmemGetAllNodeIds();
324 printf("NodeIdMask:0x%02X\n",(int) all_nodes);
325 for (i=0; i<XmemMAX_NODES; i++) {
326 msk = 1 << i;
327 if (all_nodes & msk) printf("NodeId:0x%02X: NodeName:%s\n",
328 (int) msk,
329 XmemGetNodeName((XmemNodeId) msk));
331 printf("\n");
333 nid = XmemWhoAmI();
334 if (nid) {
335 printf("This node has Id: 0x%02X NodeName:%s\n",
336 (int) nid,
337 XmemGetNodeName((XmemNodeId) nid));
339 i = XmemCheckForWarmStart();
340 if (i) printf("This is a WARM start\n");
341 else printf("This is a COLD start\n");
342 return ++arg;
345 /* ========================================================= */
346 /* Get the name od a node from its Id */
348 int GetNodeName(int arg) {
349 ArgVal *v;
350 AtomType at;
351 unsigned long nid, msk;
352 int i;
354 arg++;
355 v = &(vals[arg]);
356 at = v->Type;
357 if (at == Numeric) {
358 arg++;
359 if (v->Number) {
360 nid = v->Number;
362 } else nid = XmemGetAllNodeIds();
364 for (i=0; i<XmemMAX_NODES; i++) {
365 msk = 1 << i;
366 if (msk & nid)
367 printf("NodeId:0x%02X NodeName:%s\n",(int) msk, XmemGetNodeName((XmemNodeId) msk));
369 return ++arg;
372 /* ========================================================= */
373 /* Get the ID of a node from its name */
375 int GetNodeId(int arg) {
376 ArgVal *v;
377 AtomType at;
379 arg++;
380 v = &(vals[arg]);
381 at = v->Type;
382 if (at == Alpha) {
383 arg++;
384 printf("%s has ID:0x%X\n",
385 v->Text,
386 XmemGetNodeId(v->Text));
387 } else printf("No node name supplied\n");
388 return arg;
391 /* ========================================================= */
392 /* Get the complete list of all defined tables */
394 int GetAllTableIds(int arg) {
395 unsigned long msk;
396 int i;
398 all_tables = XmemGetAllTableIds();
399 printf("TableIds:0x%08X\n",(int) all_tables);
400 for (i=0; i<XmemMAX_TABLES; i++) {
401 msk = 1 << i;
402 if (msk & all_tables)
403 printf("TableId:0x%08X: TableName:%s\n",
404 (int) msk,
405 XmemGetTableName((XmemTableId) msk));
407 return ++arg;
410 /* ========================================================= */
411 /* Get the name of a table from its ID */
413 int GetTableName(int arg) {
414 ArgVal *v;
415 AtomType at;
416 unsigned long tid, msk;
417 int i;
419 arg++;
420 v = &(vals[arg]);
421 at = v->Type;
422 if (at == Numeric) {
423 arg++;
424 if (v->Number) {
425 tid = v->Number;
427 } else tid = XmemGetAllTableIds();
429 for (i=0; i<XmemMAX_TABLES; i++) {
430 msk = 1 << i;
431 if (msk & tid)
432 printf("TableId:0x%08X TableName:%s\n",(int) msk, XmemGetTableName((XmemTableId) msk));
434 return ++arg;
437 /* ========================================================= */
438 /* Get the ID of a table from its name */
440 int GetTableId(int arg) {
441 ArgVal *v;
442 AtomType at;
444 arg++;
445 v = &(vals[arg]);
446 at = v->Type;
447 if (at == Alpha) {
448 arg++;
449 printf("%s has ID:0x%X\n",
450 v->Text,
451 XmemGetTableId(v->Text));
452 } else printf("No table name supplied\n");
453 return arg;
456 /* ========================================================= */
457 /* Get the description of a table from its ID */
459 int GetTableDesc(int arg) {
460 ArgVal *v;
461 AtomType at;
462 unsigned long tid, nid, msk, user, longs;
463 int i;
465 arg++;
466 v = &(vals[arg]);
467 at = v->Type;
468 if (at == Numeric) {
469 arg++;
470 if (v->Number) {
471 tid = v->Number;
473 } else tid = XmemGetAllTableIds();
475 for (i=0; i<XmemMAX_TABLES; i++) {
476 msk = 1 << i;
477 if (msk & tid) {
478 XmemGetTableDesc(msk,(unsigned long *) &longs,(XmemNodeId *) &nid, &user);
479 printf("0x%08X:%s L:0x%04X[%03d] B:0x%06X[%03d] N:0x%02X U:0x%X\n",
480 (int) msk,
481 XmemGetTableName((XmemTableId) msk),
482 (int) longs,
483 (int) longs,
484 (int) longs*sizeof(long),
485 (int) longs*sizeof(long),
486 (int) nid,
487 (int) user);
490 return arg;
493 /* ========================================================= */
494 /* Wait for an event. Arg contains optional timeout */
496 int Wait(int arg) {
497 ArgVal *v;
498 AtomType at;
500 arg++;
501 v = &(vals[arg]);
502 at = v->Type;
503 if (at == Numeric) {
504 arg++;
505 if (v->Number) {
506 timeout = v->Number;
509 printf("Wait:EventMask:0x%X\n",XmemWait(timeout));
510 return arg;
513 /* ========================================================= */
514 /* Non blocking event poll */
516 int Poll(int arg) {
518 arg++;
519 if (XmemPoll() == 0) printf("Poll:No events on queue\n");
520 return arg;
523 /* ========================================================= */
524 /* Send table from shared memory */
526 int SendTable(int arg) {
527 ArgVal *v;
528 AtomType at;
529 unsigned long tid, nid, user, longs;
531 long *table;
532 XmemError err;
534 arg++;
535 v = &(vals[arg]);
536 at = v->Type;
537 tid = ctid;
538 if (at == Numeric) {
539 arg++;
540 if (v->Number) {
541 tid = v->Number;
544 table = XmemGetSharedMemory(tid);
545 if (table) {
546 ctid = tid;
547 err = XmemGetTableDesc(tid,&longs,(XmemNodeId *) &nid, &user);
548 if (err != XmemErrorSUCCESS) return arg;
549 err = XmemSendTable(tid,table,longs,0,1);
550 if (err == XmemErrorSUCCESS) printf("Sent:%s from shmem OK\n",
551 XmemGetTableName(tid));
552 else printf("Error:Table NOT sent:%s\n",
553 XmemErrorToString(err));
554 return arg;
556 printf("Can't get shared memory segment\n");
557 return arg;
560 /* ========================================================= */
561 /* Recieve table and update shared memory */
563 int RecvTable(int arg) {
564 ArgVal *v;
565 AtomType at;
566 unsigned long tid, nid, user, longs;
568 long *table;
569 XmemError err;
571 arg++;
572 v = &(vals[arg]);
573 at = v->Type;
574 tid = ctid;
575 if (at == Numeric) {
576 arg++;
577 if (v->Number) {
578 tid = v->Number;
581 table = XmemGetSharedMemory(tid);
582 if (table) {
583 ctid = tid;
584 err = XmemGetTableDesc(tid,&longs,(XmemNodeId *) &nid, &user);
585 if (err != XmemErrorSUCCESS) return arg;
586 err = XmemRecvTable(tid,table,longs,0);
587 if (err == XmemErrorSUCCESS) printf("Received:%s in shmem OK\n",
588 XmemGetTableName(tid));
589 else printf("Error:Table NOT received:%s\n",
590 XmemErrorToString(err));
591 return arg;
593 printf("Error:Can't get shared memory segment\n");
594 return arg;
597 /* ========================================================= */
598 /* Send a message */
600 int SendMessage(int arg) {
601 ArgVal *v;
602 AtomType at;
603 int i, j;
604 unsigned long dta, nid;
605 XmemMessageType mtyp;
606 XmemMessage mess;
607 XmemError err;
609 arg++;
610 v = &(vals[arg]);
611 at = v->Type;
613 if (at == Operator) {
614 if (v->OId == OprNOOP) {
615 arg++;
617 for (i=0; i<XmemMessageTypeCOUNT; i++) {
618 printf("%d:%s\t",i,MSNames[i]);
619 switch ((XmemMessageType) i) {
620 case XmemMessageTypeTABLE_UPDATE:
621 case XmemMessageTypeSEND_TABLE:
622 printf("<NdIdMask><TbIdMask>");
623 break;
625 case XmemMessageTypeUSER:
626 printf("<NdIdMask><Data>");
627 break;
629 case XmemMessageTypeINITIALIZE_ME:
630 printf("<NdIdMask><Sub:");
631 for (j=0; j<XmemInitMessageMESSAGES; j++) {
632 printf("%d:%s ",j,InitMess[j]);
634 printf("[Or greater]>");
635 break;
637 case XmemMessageTypeKILL:
638 printf("<NdIdMask>");
639 break;
641 default: break;
643 printf("\n");
646 return arg;
649 if (at == Numeric) {
650 arg++;
651 mtyp = v->Number;
652 v = &(vals[arg]);
653 at = v->Type;
654 if (mtyp >= XmemMessageTypeCOUNT) {
655 printf("Illegal message type: %d Range is [0..%d]\n",
656 (int) mtyp,
657 (int) XmemMessageTypeCOUNT -1);
658 return arg;
660 } else {
661 printf("Error:No message specified\n");
662 return arg;
665 nid = XmemWhoAmI();
666 if (at == Numeric) {
667 arg++;
668 nid = v->Number;
669 if (nid == 0) nid = XmemALL_NODES;
670 v = &(vals[arg]);
671 at = v->Type;
674 dta = 0;
675 if (at == Numeric) {
676 arg++;
677 dta = v->Number;
678 v = &(vals[arg]);
679 at = v->Type;
682 mess.MessageType = mtyp;
683 mess.Data = dta;
684 err = XmemSendMessage(nid,&mess);
685 if (err == XmemErrorSUCCESS) printf("Message:%s %d %d sent OK\n",
686 MSNames[mtyp],
687 (int) nid,
688 (int) dta);
689 else printf("Error:Message NOT sent:%s\n",
690 XmemErrorToString(err));
691 return arg;
694 /* ========================================================= */
695 /* Check for table updates */
697 int CheckTables(int arg) {
698 unsigned long tid;
699 unsigned long msk;
700 int i;
702 arg++;
703 tid = XmemCheckTables();
704 if (tid) {
705 printf("Updated: TableIdMask:0x%08X\n",(int) tid);
706 for (i=0; i<XmemMAX_TABLES; i++) {
707 msk = 1 << i;
708 if (msk & tid)
709 printf("Updated: TableId:0x%08X TableName:%s\n",
710 (int) msk,
711 XmemGetTableName((XmemTableId) msk));
713 return arg;
715 printf("Updated: 0 => No table updates since last call\n");
716 return arg;
719 /* ========================================================= */
720 /* Save a table to disc */
722 int SaveTable(int arg) {
723 ArgVal *v;
724 AtomType at;
726 XmemNodeId nodes, nid;
727 XmemTableId tid;
728 unsigned long user, longs;
729 XmemError err;
731 arg++;
732 v = &(vals[arg]);
733 at = v->Type;
735 tid = ctid;
736 if (at == Numeric) {
737 arg++;
738 tid = v->Number;
740 err = XmemGetTableDesc(tid,&longs,&nodes,&user);
741 if (err != XmemErrorSUCCESS) {
742 printf("Error:Can't get Id:0x%08x table description:%s\n",
743 (int) tid,
744 XmemErrorToString(err));
745 return arg;
747 ctid = tid;
748 nid = XmemWhoAmI();
749 if (nid & nodes) {
750 err = XmemWriteTableFile(tid);
751 if (err != XmemErrorSUCCESS) printf("Error:Can't write table to disc:%s\n",
752 XmemErrorToString(err));
753 else printf("Saved:%s to disc: OK\n",
754 XmemGetTableName(tid));
755 } else printf("Error:No write-access: File belongs to another node\n");
756 return arg;
759 /* ========================================================= */
760 /* Load a table from disc */
762 int LoadTable(int arg) {
763 ArgVal *v;
764 AtomType at;
766 XmemNodeId nodes, nid;
767 XmemTableId tid;
768 unsigned long user, longs;
769 XmemError err;
771 arg++;
772 v = &(vals[arg]);
773 at = v->Type;
774 tid = ctid;
775 if (at == Numeric) {
776 arg++;
777 tid = v->Number;
779 err = XmemGetTableDesc(tid,&longs,&nodes,&user);
780 if (err != XmemErrorSUCCESS) {
781 printf("Error:Can't get Id:0x%08x table description:%s\n",
782 (int) tid,
783 XmemErrorToString(err));
784 return arg;
786 ctid = tid;
787 nid = XmemWhoAmI();
788 if (nid & nodes) {
789 err = XmemReadTableFile(tid);
790 if (err != XmemErrorSUCCESS) printf("Error:Can't read table from disc:%s\n",
791 XmemErrorToString(err));
792 else printf("Loaded:%s from disc: OK\n",
793 XmemGetTableName(tid));
794 } else printf("Error:This node should receive the table from memory, not disc\n");
795 return arg;
798 /*****************************************************************/
800 void EditMemory(char *name, unsigned long *table, unsigned long longs, int flag) {
802 unsigned long addr, data, nadr;
803 char c, *cp, str[128];
804 int n, radix, cnt;
806 printf("EditMemory: ?:Comment /:Open CR:Next .:Exit x:Hex d:Dec s:String\n\n");
808 addr = 0;
809 radix = 16;
811 c = '\n';
813 while (1) {
815 printf("%s ",name);
816 if (radix == 16) {
817 if (c=='\n') printf("Addr:0x%04x: 0x%04x ",(int) addr,(int) table[addr]);
818 } else {
819 if (c=='\n') printf("Addr:%04d: %5d ",(int) addr,(int) table[addr]);
822 c = (char) getchar();
824 if (c == '/') {
825 bzero((void *) str, 128); n = 0;
826 while ((c != '\n') && (n < 128)) c = str[n++] = (char) getchar();
827 nadr = strtoul(str,&cp,radix);
828 if (cp != str) addr = nadr;
831 else if (c == 'x') { radix = 16; addr--; continue; }
832 else if (c == 'd') { radix = 10; addr--; continue; }
833 else if (c == '.') { c = getchar(); printf("\n"); break; }
834 else if (c == 'q') { c = getchar(); printf("\n"); break; }
835 else if (c == 's') {
836 cnt = 0; cp = (char *) &(table[addr]);
837 while ((c = (char) getchar()) != '\n') {
838 cp[0] = c;
839 cp[1] = '\0';
840 if (cnt++ > 32) break;
841 cp++;
843 cnt = 0; cp = (char *) &(table[addr]);
844 while (isascii((int) *cp)) {
845 putchar(*cp);
846 if ((*cp == '\0') || (*cp == '\n') || (cnt++ > 32)) break;
847 cp++;
849 printf("\n");
850 continue;
851 } else if (c == '\n') {
852 addr++;
853 if (addr >= longs) {
854 addr = 0;
855 printf("\n===\n");
858 else {
859 bzero((void *) str, 128); n = 0;
860 str[n++] = c;
861 while ((c != '\n') && (n < 128)) c = str[n++] = (char) getchar();
862 data = strtoul(str,&cp,radix);
863 if (cp != str) {
864 if (flag) table[addr] = data;
865 else printf("\7");
871 /* ========================================================= */
872 /* Edit shared memory */
874 int EditSharedMemory(int arg) {
875 ArgVal *v;
876 AtomType at;
878 XmemNodeId nodes, nid;
879 XmemTableId tid;
880 unsigned long user, longs;
881 XmemError err;
882 unsigned long *table;
883 char *name;
885 arg++;
886 v = &(vals[arg]);
887 at = v->Type;
889 tid = ctid;
890 if (at == Numeric) {
891 arg++;
892 tid = v->Number;
894 table = XmemGetSharedMemory(tid);
895 if (table) {
896 ctid = tid;
897 err = XmemGetTableDesc(tid,&longs,&nodes,&user);
898 if (err != XmemErrorSUCCESS) {
899 printf("Error:Can't get Id:0x%08x table description:%s\n",
900 (int) tid,
901 XmemErrorToString(err));
902 return arg;
904 nid = XmemWhoAmI();
905 name = XmemGetTableName(tid);
906 if (nid & nodes) {
907 printf("Editing: %s in RW mode: FULL-ACCESS\n",name);
908 EditMemory(name,table,longs,1);
909 } else {
910 printf("Editing: %s in RO mode: No WRITE-ACCESS\n",name);
911 EditMemory(name,table,longs,0);
914 return arg;
917 /* ========================================================= */
918 /* Show what in the shared memory segment */
920 int ShowDaemonEventLog(int arg) {
922 XdEventLogEntry *evp;
923 int i;
925 arg++;
926 event_log = GetEventLogTable();
927 if (event_log) {
928 if (event_log->NextEntry) {
929 for (i=0; i<event_log->NextEntry; i++) {
930 evp = &(event_log->Entries[i]);
931 printf("%02d: %s ",i,TimeToStr(evp->Time));
932 printf("%s: ",CallbackToStr(&(evp->CbEvent)));
933 if (evp->Text) printf("%s",(char *) &(evp->Text[0]));
934 printf("\n");
936 } else printf("Empty: No logged events in memory\n");
938 return arg;
941 /* ========================================================= */
942 /* Print out the file for a node */
944 int ShowDaemonEventHistory(int arg) {
946 ArgVal *v;
947 AtomType at;
948 XdEventLogEntries elog;
949 XdEventLogEntry *evp;
950 int i, cnt;
951 char *elg;
952 FILE *fp;
953 XmemNodeId nid;
955 arg++;
956 v = &(vals[arg]);
957 at = v->Type;
958 nid = XmemWhoAmI();
959 if (at == Numeric) {
960 arg++;
961 nid = v->Number;
963 umask(0);
964 elg = XmemGetFile(EVENT_LOG);
965 fp = fopen(elg,"r");
966 if (fp) {
967 bzero((void *) &elog, sizeof(XdEventLogEntries));
968 cnt = fread(&elog, sizeof(XdEventLogEntries), 1, fp);
969 if (cnt <= 0) {
970 perror("ShowDaemonEventHistory");
971 fprintf(stderr,"ShowDaemonEventHistory: Error: Can't READ:%s\n",elg);
972 fclose(fp);
973 return arg;
975 } else {
976 perror("ShowDaemonEventHistory");
977 fprintf(stderr,"ShowDaemonEventHistory: Error: Can't OPEN:%s for READ\n",elg);
978 return arg;
980 fclose(fp);
982 printf("Showing file:%s\n",elg);
983 for (i=0; i<elog.NextEntry; i++) {
984 evp = &(elog.Entries[i]);
985 printf("%02d: %s ",i,TimeToStr(evp->Time));
986 printf("%s: ",CallbackToStr(&(evp->CbEvent)));
987 if (evp->Text) printf("%s",(char *) &(evp->Text[0]));
988 printf("\n");
990 return arg;
993 /* ========================================================= */
994 /* Wipe errors out */
996 int ClearDaemonEventLog(int arg) {
998 arg++;
1000 event_log = GetEventLogTable();
1001 if (event_log) {
1002 bzero((void *) event_log, sizeof(XdEventLogEntries));
1003 printf("ClearDaemonEventLog: Done OK\n");
1004 return arg;
1006 return arg;
1009 /* ========================================================= */
1011 int KillDaemon(int arg) {
1013 ArgVal *v;
1014 AtomType at;
1015 XmemMessage mes;
1016 XmemNodeId nid;
1017 XmemError err;
1019 arg++;
1020 v = &(vals[arg]);
1021 at = v->Type;
1022 nid = XmemWhoAmI();
1023 if (at == Numeric) {
1024 arg++;
1025 nid = v->Number;
1026 if (nid == 0) nid = XmemALL_NODES;
1028 mes.MessageType = XmemMessageTypeKILL;
1029 mes.Data = XmemWhoAmI();
1030 err = XmemSendMessage(nid,&mes);
1031 if (err == XmemErrorSUCCESS) printf("Sent KILL to nodes: 0x%02X\n",(int) nid);
1032 else printf("KillDaemon: Error: %s\n",XmemErrorToString(err));
1033 return arg;
1036 /* ========================================================= */
1038 int Init(int arg) {
1040 XmemMessage mes;
1041 XmemError err;
1043 arg++;
1045 mes.MessageType = XmemMessageTypeINITIALIZE_ME;
1046 mes.Data = XmemInitMessageRESET;
1047 err = XmemSendMessage(XmemALL_NODES,&mes);
1048 if (err == XmemErrorSUCCESS) printf("Sent Initialize to all nodes");
1049 else printf("Init: Error: %s\n",XmemErrorToString(err));
1050 return arg;