~ubuntu-branches/ubuntu/vivid/slurm-llnl/vivid

« back to all changes in this revision

Viewing changes to src/scontrol/scontrol.c

  • Committer: Bazaar Package Importer
  • Author(s): Gennaro Oliva
  • Date: 2009-09-24 23:28:15 UTC
  • mfrom: (1.1.11 upstream) (3.2.4 sid)
  • Revision ID: james.westby@ubuntu.com-20090924232815-enh65jn32q1ebg07
Tags: 2.0.5-1
* New upstream release 
* Changed dependecy from lib-mysqlclient15 to lib-mysqlclient 
* Added Default-Start for runlevel 2 and 4 and $remote_fs requirement in
  init.d scripts (Closes: #541252)
* Postinst checks for wrong runlevels 2 and 4 links
* Upgraded to standard version 3.8.3
* Add lintian overrides for missing slurm-llnl-configurator.html in doc
  base registration
* modified postrm scripts to ignore pkill return value in order to avoid
  postrm failure when no slurm process is running
* Checking for slurmctld.pid before cancelling running and pending
  jobs during package removal 

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 *      provides interface to read, write, update, and configurations.
4
4
 *****************************************************************************
5
5
 *  Copyright (C) 2002-2007 The Regents of the University of California.
6
 
 *  Copyright (C) 2008 Lawrence Livermore National Security.
 
6
 *  Copyright (C) 2008-2009 Lawrence Livermore National Security.
7
7
 *  Portions Copyright (C) 2008 Vijay Ramasubramanian.
8
8
 *  Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
9
9
 *  Written by Morris Jette <jette1@llnl.gov>
10
 
 *  LLNL-CODE-402394.
 
10
 *  CODE-OCEC-09-009. All rights reserved.
11
11
 *  
12
12
 *  This file is part of SLURM, a resource management program.
13
 
 *  For details, see <http://www.llnl.gov/linux/slurm/>.
 
13
 *  For details, see <https://computing.llnl.gov/linux/slurm/>.
 
14
 *  Please also read the included file: DISCLAIMER.
14
15
 *  
15
16
 *  SLURM is free software; you can redistribute it and/or modify it under
16
17
 *  the terms of the GNU General Public License as published by the Free
51
52
int quiet_flag;         /* quiet=1, verbose=-1, normal=0 */
52
53
int verbosity;          /* count of "-v" options */
53
54
 
 
55
static void     _create_it (int argc, char *argv[]);
54
56
static void     _delete_it (int argc, char *argv[]);
 
57
static void     _show_it (int argc, char *argv[]);
55
58
static int      _get_command (int *argc, char *argv[]);
56
59
static void     _ping_slurmctld(char *control_machine, char *backup_controller);
57
60
static void     _print_config (char *config_param);
195
198
 
196
199
        printf("%s", prompt);
197
200
 
198
 
        fgets(buf, 4096, stdin);
 
201
        /* we only set this here to avoid a warning.  We throw it away
 
202
           later. */
 
203
        line = fgets(buf, 4096, stdin);
 
204
 
199
205
        len = strlen(buf);
200
206
        if ((len > 0) && (buf[len-1] == '\n'))
201
207
                buf[len-1] = '\0';
457
463
_process_command (int argc, char *argv[]) 
458
464
{
459
465
        int error_code = 0;
 
466
        char *tag = argv[0];
 
467
        int taglen = 0;
460
468
 
461
469
        if (argc < 1) {
462
470
                exit_code = 1;
463
471
                if (quiet_flag == -1)
464
472
                        fprintf(stderr, "no input");
 
473
                return 0;
 
474
        } else if(tag)
 
475
                taglen = strlen(tag);
 
476
        else {
 
477
                if (quiet_flag == -1)
 
478
                        fprintf(stderr, "input problem");
 
479
                return 0;
465
480
        }
466
 
        else if (strncasecmp (argv[0], "abort", 5) == 0) {
 
481
 
 
482
if (strncasecmp (tag, "abort", MAX(taglen, 5)) == 0) {
467
483
                /* require full command name */
468
484
                if (argc > 2) {
469
485
                        exit_code = 1;
470
486
                        fprintf (stderr,
471
487
                                 "too many arguments for keyword:%s\n", 
472
 
                                 argv[0]);
 
488
                                 tag);
473
489
                }
474
490
                error_code = slurm_shutdown (1);
475
491
                if (error_code) {
478
494
                                slurm_perror ("slurm_shutdown error");
479
495
                }
480
496
        }
481
 
        else if (strncasecmp (argv[0], "all", 3) == 0)
 
497
        else if (strncasecmp (tag, "all", MAX(taglen, 2)) == 0)
482
498
                all_flag = 1;
483
 
        else if (strncasecmp (argv[0], "completing", 3) == 0) {
 
499
        else if (strncasecmp (tag, "completing", MAX(taglen, 2)) == 0) {
484
500
                if (argc > 1) {
485
501
                        exit_code = 1;
486
502
                        fprintf (stderr, 
487
503
                                 "too many arguments for keyword:%s\n", 
488
 
                                 argv[0]);
 
504
                                 tag);
489
505
                }
490
506
                scontrol_print_completing();
491
507
        }
492
 
        else if (strncasecmp (argv[0], "exit", 1) == 0) {
 
508
        else if (strncasecmp (tag, "create", MAX(taglen, 2)) == 0) {
 
509
                if (argc < 2) {
 
510
                        exit_code = 1;
 
511
                        fprintf (stderr, "too few arguments for %s keyword\n",
 
512
                                 tag);
 
513
                        return 0;
 
514
                }               
 
515
                _create_it ((argc - 1), &argv[1]);
 
516
        }
 
517
        else if (strncasecmp (tag, "exit", MAX(taglen, 1)) == 0) {
493
518
                if (argc > 1) {
494
519
                        exit_code = 1;
495
520
                        fprintf (stderr, 
496
521
                                 "too many arguments for keyword:%s\n", 
497
 
                                 argv[0]);
 
522
                                 tag);
498
523
                }
499
524
                exit_flag = 1;
500
525
        }
501
 
        else if (strncasecmp (argv[0], "help", 2) == 0) {
 
526
        else if (strncasecmp (tag, "help", MAX(taglen, 2)) == 0) {
502
527
                if (argc > 1) {
503
528
                        exit_code = 1;
504
529
                        fprintf (stderr, 
505
530
                                 "too many arguments for keyword:%s\n",
506
 
                                 argv[0]);
 
531
                                 tag);
507
532
                }
508
533
                _usage ();
509
534
        }
510
 
        else if (strncasecmp (argv[0], "hide", 2) == 0)
 
535
        else if (strncasecmp (tag, "hide", MAX(taglen, 2)) == 0)
511
536
                all_flag = 0;
512
 
        else if (strncasecmp (argv[0], "oneliner", 1) == 0) {
 
537
        else if (strncasecmp (tag, "oneliner", MAX(taglen, 1)) == 0) {
513
538
                if (argc > 1) {
514
539
                        exit_code = 1;
515
540
                        fprintf (stderr, 
516
541
                                 "too many arguments for keyword:%s\n",
517
 
                                 argv[0]);
 
542
                                 tag);
518
543
                }
519
544
                one_liner = 1;
520
545
        }
521
 
        else if (strncasecmp (argv[0], "pidinfo", 3) == 0) {
 
546
        else if (strncasecmp (tag, "pidinfo", MAX(taglen, 3)) == 0) {
522
547
                if (argc > 2) {
523
548
                        exit_code = 1;
524
549
                        fprintf (stderr, 
525
550
                                 "too many arguments for keyword:%s\n", 
526
 
                                 argv[0]);
 
551
                                 tag);
527
552
                } else if (argc < 2) {
528
553
                        exit_code = 1;
529
554
                        fprintf (stderr, 
530
555
                                 "missing argument for keyword:%s\n", 
531
 
                                 argv[0]);
 
556
                                 tag);
532
557
                } else
533
558
                        scontrol_pid_info ((pid_t) atol (argv[1]) );
534
559
        }
535
 
        else if (strncasecmp (argv[0], "ping", 3) == 0) {
 
560
        else if (strncasecmp (tag, "ping", MAX(taglen, 3)) == 0) {
536
561
                if (argc > 1) {
537
562
                        exit_code = 1;
538
563
                        fprintf (stderr, 
539
564
                                 "too many arguments for keyword:%s\n",
540
 
                                 argv[0]);
 
565
                                 tag);
541
566
                }
542
567
                _print_ping ();
543
568
        }
544
 
        else if ((strncasecmp (argv[0], "\\q", 2) == 0) ||
545
 
                 (strncasecmp (argv[0], "quiet", 4) == 0)) {
 
569
        else if ((strncasecmp (tag, "\\q", 2) == 0) ||
 
570
                 (strncasecmp (tag, "quiet", MAX(taglen, 4)) == 0)) {
546
571
                if (argc > 1) {
547
572
                        exit_code = 1;
548
573
                        fprintf (stderr, "too many arguments for keyword:%s\n",
549
 
                                 argv[0]);
 
574
                                 tag);
550
575
                }
551
576
                quiet_flag = 1;
552
577
        }
553
 
        else if (strncasecmp (argv[0], "quit", 4) == 0) {
 
578
        else if (strncasecmp (tag, "quit", MAX(taglen, 4)) == 0) {
554
579
                if (argc > 1) {
555
580
                        exit_code = 1;
556
581
                        fprintf (stderr, 
557
582
                                 "too many arguments for keyword:%s\n", 
558
 
                                 argv[0]);
 
583
                                 tag);
559
584
                }
560
585
                exit_flag = 1;
561
586
        }
562
 
        else if (strncasecmp (argv[0], "reconfigure", 3) == 0) {
 
587
        else if (strncasecmp (tag, "reconfigure", MAX(taglen, 3)) == 0) {
563
588
                if (argc > 2) {
564
589
                        exit_code = 1;
565
590
                        fprintf (stderr, "too many arguments for keyword:%s\n",
566
 
                                 argv[0]);
 
591
                                 tag);
567
592
                }
568
593
                error_code = slurm_reconfigure ();
569
594
                if (error_code) {
572
597
                                slurm_perror ("slurm_reconfigure error");
573
598
                }
574
599
        }
575
 
        else if (strncasecmp (argv[0], "checkpoint", 5) == 0) {
576
 
                if (argc > 3) {
 
600
        else if (strncasecmp (tag, "checkpoint", MAX(taglen, 2)) == 0) {
 
601
                if (argc > 5) {
577
602
                        exit_code = 1;
578
603
                        if (quiet_flag != 1)
579
604
                                fprintf(stderr, 
580
605
                                        "too many arguments for keyword:%s\n", 
581
 
                                        argv[0]);
 
606
                                        tag);
582
607
                }
583
608
                else if (argc < 3) {
584
609
                        exit_code = 1;
585
610
                        if (quiet_flag != 1)
586
611
                                fprintf(stderr, 
587
612
                                        "too few arguments for keyword:%s\n", 
588
 
                                        argv[0]);
 
613
                                        tag);
589
614
                }
590
615
                else {
591
 
                        error_code = scontrol_checkpoint(argv[1], argv[2]);
 
616
                        error_code = scontrol_checkpoint(argv[1], argv[2], 
 
617
                                                         argc - 3, &argv[3]);
592
618
                        if (error_code) {
593
619
                                exit_code = 1;
594
620
                                if (quiet_flag != 1)
595
 
                                        slurm_perror ("slurm_checkpoint error");
 
621
                                        slurm_perror ("scontrol_checkpoint error");
596
622
                        }
597
623
                }
598
624
        }
599
 
        else if (strncasecmp (argv[0], "requeue", 3) == 0) {
 
625
        else if (strncasecmp (tag, "requeue", MAX(taglen, 3)) == 0) {
600
626
                if (argc > 2) {
601
627
                        exit_code = 1;
602
628
                        if (quiet_flag != 1)
603
629
                                fprintf(stderr,
604
630
                                        "too many arguments for keyword:%s\n",
605
 
                                        argv[0]);
 
631
                                        tag);
606
632
                } else if (argc < 2) {
607
633
                        exit_code = 1;
608
634
                        if (quiet_flag != 1)
609
635
                                fprintf(stderr,
610
636
                                        "too few arguments for keyword:%s\n",
611
 
                                        argv[0]);
 
637
                                        tag);
612
638
                } else {
613
639
                        error_code = scontrol_requeue(argv[1]);
614
640
                        if (error_code) {
619
645
                }
620
646
                                
621
647
        }
622
 
        else if ((strncasecmp (argv[0], "suspend", 3) == 0)
623
 
        ||       (strncasecmp (argv[0], "resume", 3) == 0)) {
 
648
        else if ((strncasecmp (tag, "suspend", MAX(taglen, 2)) == 0)
 
649
        ||       (strncasecmp (tag, "resume", MAX(taglen, 3)) == 0)) {
624
650
                if (argc > 2) {
625
651
                        exit_code = 1;
626
652
                        if (quiet_flag != 1)
627
653
                                fprintf(stderr,
628
654
                                        "too many arguments for keyword:%s\n",
629
 
                                        argv[0]);
 
655
                                        tag);
630
656
                }
631
657
                else if (argc < 2) {
632
658
                        exit_code = 1;
633
659
                        if (quiet_flag != 1)
634
660
                                fprintf(stderr,
635
661
                                        "too few arguments for keyword:%s\n",
636
 
                                        argv[0]);
 
662
                                        tag);
637
663
                } else {
638
664
                        error_code =scontrol_suspend(argv[0], argv[1]);
639
665
                        if (error_code) {
643
669
                        }
644
670
                }
645
671
        }
646
 
        else if (strncasecmp (argv[0], "setdebug", 4) == 0) {
 
672
        else if (strncasecmp (tag, "setdebug", MAX(taglen, 2)) == 0) {
647
673
                if (argc > 2) {
648
674
                        exit_code = 1;
649
675
                        if (quiet_flag != 1)
650
 
                                fprintf(stderr, "too many arguments for keyword:%s\n",
651
 
                                        argv[0]);
 
676
                                fprintf(stderr, 
 
677
                                        "too many arguments for keyword:%s\n",
 
678
                                        tag);
652
679
                } else if (argc < 2) {
653
680
                        exit_code = 1;
654
681
                        if (quiet_flag != 1)
655
 
                                fprintf(stderr, "too few arguments for keyword:%s\n",
656
 
                                        argv[0]);
 
682
                                fprintf(stderr, 
 
683
                                        "too few arguments for keyword:%s\n",
 
684
                                        tag);
657
685
                } else {
658
686
                        int level = -1;
659
687
                        char *endptr;
660
688
                        char *levels[] = {
661
689
                                "quiet", "fatal", "error", "info", "verbose",
662
 
                                "debug", "debug2", "debug3", "debug4", "debug5", NULL};
 
690
                                "debug", "debug2", "debug3", "debug4", 
 
691
                                "debug5", NULL};
663
692
                        int index = 0;
664
693
                        while (levels[index]) {
665
694
                                if (strcasecmp(argv[1], levels[index]) == 0) {
669
698
                                index ++;
670
699
                        }
671
700
                        if (level == -1) {
672
 
                                level = (int)strtoul (argv[1], &endptr, 10);    /* effective levels: 0 - 9 */
 
701
                                /* effective levels: 0 - 9 */
 
702
                                level = (int)strtoul (argv[1], &endptr, 10);
673
703
                                if (*endptr != '\0' || level > 9) {
674
704
                                        level = -1;
675
705
                                        exit_code = 1;
676
706
                                        if (quiet_flag != 1)
677
 
                                                fprintf(stderr, "invalid debug level: %s\n",
678
 
                                                        argv[1]);
 
707
                                                fprintf(stderr, "invalid debug "
 
708
                                                        "level: %s\n", argv[1]);
679
709
                                }
680
710
                        }
681
711
                        if (level != -1) {
688
718
                        }
689
719
                }
690
720
        }
691
 
        else if (strncasecmp (argv[0], "show", 3) == 0) {
692
 
                if (argc > 3) {
693
 
                        exit_code = 1;
694
 
                        if (quiet_flag != 1)
695
 
                                fprintf(stderr, 
696
 
                                        "too many arguments for keyword:%s\n", 
697
 
                                        argv[0]);
698
 
                }
699
 
                else if (argc < 2) {
700
 
                        exit_code = 1;
701
 
                        if (quiet_flag != 1)
702
 
                                fprintf(stderr, 
703
 
                                        "too few arguments for keyword:%s\n", 
704
 
                                        argv[0]);
705
 
                }
706
 
                else if (strncasecmp (argv[1], "config", 3) == 0) {
707
 
                        if (argc > 2)
708
 
                                _print_config (argv[2]);
709
 
                        else
710
 
                                _print_config (NULL);
711
 
                }
712
 
                else if (strncasecmp (argv[1], "daemons", 3) == 0) {
713
 
                        if (argc > 2) {
 
721
        else if (strncasecmp (tag, "show", MAX(taglen, 3)) == 0) {
 
722
                _show_it (argc, argv);
 
723
        }
 
724
        else if (strncasecmp (tag, "takeover", MAX(taglen, 8)) == 0) {
 
725
                char *secondary = NULL;
 
726
                slurm_ctl_conf_info_msg_t  *slurm_ctl_conf_ptr = NULL;
 
727
 
 
728
                slurm_ctl_conf_ptr = slurm_conf_lock();
 
729
                secondary = xstrdup(slurm_ctl_conf_ptr->backup_controller);
 
730
                slurm_conf_unlock();
 
731
 
 
732
                if ( secondary && secondary[0] != '\0' ) {
 
733
                        error_code = slurm_takeover();
 
734
                        if (error_code) {
714
735
                                exit_code = 1;
715
736
                                if (quiet_flag != 1)
716
 
                                        fprintf(stderr,
717
 
                                                "too many arguments for keyword:%s\n", 
718
 
                                                argv[0]);
 
737
                                        slurm_perror("slurm_takeover error");
719
738
                        }
720
 
                        _print_daemons ();
721
 
                }
722
 
                else if (strncasecmp (argv[1], "jobs", 3) == 0) {
723
 
                        if (argc > 2)
724
 
                                scontrol_print_job (argv[2]);
725
 
                        else
726
 
                                scontrol_print_job (NULL);
727
 
                }
728
 
                else if (strncasecmp (argv[1], "hostnames", 5) == 0) {
729
 
                        if (argc > 2)
730
 
                                scontrol_print_hosts(argv[2]);
731
 
                        else
732
 
                                scontrol_print_hosts(getenv("SLURM_NODELIST"));
733
 
                }
734
 
                else if (strncasecmp (argv[1], "hostlist", 5) == 0) {
735
 
                        if (argc != 3) {
736
 
                                exit_code = 1;
737
 
                                fprintf(stderr, "invalid encode argument\n");
738
 
                                _usage();
739
 
                        } else if (scontrol_encode_hostlist(argv[2]))
740
 
                                exit_code = 1;
741
 
                }
742
 
                else if (strncasecmp (argv[1], "nodes", 3) == 0) {
743
 
                        if (argc > 2)
744
 
                                scontrol_print_node_list (argv[2]);
745
 
                        else
746
 
                                scontrol_print_node_list (NULL);
747
 
                }
748
 
                else if (strncasecmp (argv[1], "partitions", 3) == 0) {
749
 
                        if (argc > 2)
750
 
                                scontrol_print_part (argv[2]);
751
 
                        else
752
 
                                scontrol_print_part (NULL);
753
 
                }
754
 
                else if (strncasecmp (argv[1], "slurmd", 6) == 0) {
755
 
                        if (argc > 2)
756
 
                                _print_slurmd(argv[2]);
757
 
                        else
758
 
                                _print_slurmd(NULL);
759
 
                }
760
 
                else if (strncasecmp (argv[1], "steps", 3) == 0) {
761
 
                        if (argc > 2)
762
 
                                scontrol_print_step (argv[2]);
763
 
                        else
764
 
                                scontrol_print_step (NULL);
765
 
                }
766
 
                else {
767
 
                        exit_code = 1;
768
 
                        if (quiet_flag != 1)
769
 
                                fprintf (stderr,
770
 
                                         "invalid entity:%s for keyword:%s \n",
771
 
                                         argv[1], argv[0]);
772
 
                }               
773
 
 
 
739
                } else {
 
740
                        fprintf(stderr, "slurm_takeover error: no backup "
 
741
                                "controller defined\n");
 
742
                }
 
743
                xfree(secondary);
774
744
        }
775
 
        else if (strncasecmp (argv[0], "shutdown", 8) == 0) {
 
745
        else if (strncasecmp (tag, "shutdown", MAX(taglen, 8)) == 0) {
776
746
                /* require full command name */
777
747
                uint16_t options = 0;
778
748
                if (argc == 2) {
790
760
                        exit_code = 1;
791
761
                        fprintf (stderr,
792
762
                                 "too many arguments for keyword:%s\n", 
793
 
                                 argv[0]);
 
763
                                 tag);
794
764
                }
795
765
                if (error_code == 0) {
796
766
                        error_code = slurm_shutdown(options);
801
771
                        }
802
772
                }
803
773
        }
804
 
        else if (strncasecmp (argv[0], "update", 1) == 0) {
 
774
        else if (strncasecmp (tag, "update", MAX(taglen, 1)) == 0) {
805
775
                if (argc < 2) {
806
776
                        exit_code = 1;
807
777
                        fprintf (stderr, "too few arguments for %s keyword\n",
808
 
                                 argv[0]);
 
778
                                 tag);
809
779
                        return 0;
810
780
                }               
811
781
                _update_it ((argc - 1), &argv[1]);
812
782
        }
813
 
        else if (strncasecmp (argv[0], "delete", 3) == 0) {
 
783
        else if (strncasecmp (tag, "delete", MAX(taglen, 1)) == 0) {
814
784
                if (argc < 2) {
815
785
                        exit_code = 1;
816
786
                        fprintf (stderr, "too few arguments for %s keyword\n",
817
 
                                 argv[0]);
 
787
                                 tag);
818
788
                        return 0;
819
789
                }
820
790
                _delete_it ((argc - 1), &argv[1]);
821
791
        }
822
 
        else if (strncasecmp (argv[0], "verbose", 4) == 0) {
 
792
        else if (strncasecmp (tag, "verbose", MAX(taglen, 4)) == 0) {
823
793
                if (argc > 1) {
824
794
                        exit_code = 1;
825
795
                        fprintf (stderr,
826
796
                                 "too many arguments for %s keyword\n",
827
 
                                 argv[0]);
 
797
                                 tag);
828
798
                }               
829
799
                quiet_flag = -1;
830
800
        }
831
 
        else if (strncasecmp (argv[0], "version", 4) == 0) {
 
801
        else if (strncasecmp (tag, "version", MAX(taglen, 4)) == 0) {
832
802
                if (argc > 1) {
833
803
                        exit_code = 1;
834
804
                        fprintf (stderr,
835
805
                                 "too many arguments for %s keyword\n",
836
 
                                 argv[0]);
 
806
                                 tag);
837
807
                }               
838
808
                _print_version();
839
809
        }
840
 
        else if (strncasecmp (argv[0], "listpids", 8) == 0) {
 
810
        else if (strncasecmp (tag, "listpids", MAX(taglen, 1)) == 0) {
841
811
                if (argc > 3) {
842
812
                        exit_code = 1;
843
813
                        fprintf (stderr, 
844
814
                                 "too many arguments for keyword:%s\n", 
845
 
                                 argv[0]);
 
815
                                 tag);
846
816
                } else {
847
817
                        scontrol_list_pids (argc == 1 ? NULL : argv[1],
848
818
                                            argc <= 2 ? NULL : argv[2]);
849
819
                }
850
820
        }
851
 
        else if (strncasecmp (argv[0], "notify", 6) == 0) {
 
821
        else if (strncasecmp (tag, "notify", MAX(taglen, 1)) == 0) {
852
822
                if (argc < 3) {
853
823
                        exit_code = 1;
854
824
                        fprintf (stderr, 
855
825
                                 "too few arguments for keyword:%s\n", 
856
 
                                 argv[0]);
 
826
                                 tag);
857
827
                } else if (scontrol_job_notify(argc-1, &argv[1])) {
858
828
                        exit_code = 1;
859
829
                        slurm_perror("job notify failure");
861
831
        }
862
832
        else {
863
833
                exit_code = 1;
864
 
                fprintf (stderr, "invalid keyword: %s\n", argv[0]);
 
834
                fprintf (stderr, "invalid keyword: %s\n", tag);
865
835
        }
866
836
 
867
837
        return 0;
868
838
}
869
839
 
870
 
/* 
871
 
 * _delete_it - delete the slurm the specified slurm entity 
 
840
 
 
841
/* 
 
842
 * _create_it - create a slurm configuration per the supplied arguments 
 
843
 * IN argc - count of arguments
 
844
 * IN argv - list of arguments
 
845
 */
 
846
static void
 
847
_create_it (int argc, char *argv[]) 
 
848
{
 
849
        /* Scan for "res" first, anywhere in the args.  When creating
 
850
           a reservation there is a partition= option, which we don't
 
851
           want to mistake for a requestion to create a partition. */
 
852
        int i, error_code = SLURM_SUCCESS;
 
853
        for (i=0; i<argc; i++) {
 
854
                char *tag = argv[i];
 
855
                char *val = strchr(argv[i], '=');
 
856
                int taglen;
 
857
 
 
858
                if (val) {
 
859
                        taglen = val - argv[i];
 
860
                        val++;
 
861
                } else {
 
862
                        taglen = strlen(tag);
 
863
                }
 
864
                if (!strncasecmp(tag, "ReservationName", MAX(taglen, 3))) {
 
865
                        error_code = scontrol_create_res(argc, argv);
 
866
                        break;
 
867
                } else if (!strncasecmp(tag, "PartitionName", MAX(taglen, 3))) {
 
868
                        error_code = scontrol_create_part(argc, argv);
 
869
                        break;
 
870
                }
 
871
        }
 
872
 
 
873
        if (i >= argc) {
 
874
                exit_code = 1;
 
875
                error("Invalid creation entity: %s\n", argv[0]);
 
876
        } else if (error_code) 
 
877
                exit_code = 1;
 
878
}
 
879
 
 
880
 
 
881
 
 
882
 
 
883
/* 
 
884
 * _delete_it - delete the specified slurm entity 
872
885
 * IN argc - count of arguments
873
886
 * IN argv - list of arguments
874
887
 */
875
888
static void
876
889
_delete_it (int argc, char *argv[]) 
877
890
{
878
 
        delete_part_msg_t part_msg;
 
891
        char *tag = NULL, *val = NULL;
 
892
        int taglen = 0;
 
893
 
 
894
        if (argc != 1) {
 
895
                error("Only one option follows delete.  %d given.\n", argc);
 
896
                exit_code = 1;
 
897
                return;
 
898
        }
 
899
 
 
900
        tag = argv[0];
 
901
        val = strchr(argv[0], '=');
 
902
        if (val) {
 
903
                taglen = val - argv[0];
 
904
                val++;
 
905
        } else {
 
906
                error("Proper format is 'delete Partition=p'"
 
907
                      " or 'delete Reservation=r'\n");
 
908
                exit_code = 1;
 
909
                return;
 
910
        }
879
911
 
880
912
        /* First identify the entity type to delete */
881
 
        if (strncasecmp (argv[0], "PartitionName=", 14) == 0) {
882
 
                part_msg.name = argv[0] + 14;
 
913
        if (strncasecmp (tag, "PartitionName", MAX(taglen, 1)) == 0) {
 
914
                delete_part_msg_t part_msg;
 
915
                part_msg.name = val;
883
916
                if (slurm_delete_partition(&part_msg)) {
884
917
                        char errmsg[64];
885
918
                        snprintf(errmsg, 64, "delete_partition %s", argv[0]);
886
919
                        slurm_perror(errmsg);
887
920
                }
888
 
        } else {
889
 
                exit_code = 1;
890
 
                fprintf(stderr, "Invalid deletion entity: %s\n", argv[1]);
891
 
        }
892
 
}
 
921
        } else if (strncasecmp (tag, "ReservationName", MAX(taglen, 1)) == 0) {
 
922
                reservation_name_msg_t   res_msg;
 
923
                res_msg.name = val;
 
924
                if (slurm_delete_reservation(&res_msg)) {
 
925
                        char errmsg[64];
 
926
                        snprintf(errmsg, 64, "delete_reservation %s", argv[0]);
 
927
                        slurm_perror(errmsg);
 
928
                }
 
929
        } else {
 
930
                exit_code = 1;
 
931
                fprintf(stderr, "Invalid deletion entity: %s\n", argv[0]);
 
932
        }
 
933
}
 
934
 
 
935
 
 
936
/* 
 
937
 * _show_it - print a description of the specified slurm entity 
 
938
 * IN argc - count of arguments
 
939
 * IN argv - list of arguments
 
940
 */
 
941
static void
 
942
_show_it (int argc, char *argv[])
 
943
{
 
944
        char *tag = NULL, *val = NULL;
 
945
        int taglen = 0;
 
946
 
 
947
        if (argc > 3) {
 
948
                exit_code = 1;
 
949
                if (quiet_flag != 1)
 
950
                        fprintf(stderr, 
 
951
                                "too many arguments for keyword:%s\n", 
 
952
                                argv[0]);
 
953
                return;
 
954
        }
 
955
        else if (argc < 2) {
 
956
                exit_code = 1;
 
957
                if (quiet_flag != 1)
 
958
                        fprintf(stderr, 
 
959
                                "too few arguments for keyword:%s\n", argv[0]);
 
960
                return;
 
961
        }
 
962
 
 
963
        tag = argv[1];
 
964
        taglen = strlen(tag);
 
965
        val = strchr(argv[1], '=');
 
966
        if (val) {
 
967
                taglen = val - argv[1];
 
968
                val++;
 
969
        } else if (argc == 3) {
 
970
                val = argv[2];
 
971
        } else {
 
972
                val = NULL;
 
973
        }
 
974
 
 
975
        if (strncasecmp (tag, "config", MAX(taglen, 1)) == 0) {
 
976
                _print_config (val);
 
977
        }
 
978
        else if (strncasecmp (tag, "daemons", MAX(taglen, 1)) == 0) {
 
979
                if (val) {
 
980
                        exit_code = 1;
 
981
                        if (quiet_flag != 1)
 
982
                                fprintf(stderr,
 
983
                                        "too many arguments for keyword:%s\n", 
 
984
                                        argv[0]);
 
985
                }
 
986
                _print_daemons ();
 
987
        }
 
988
        else if (strncasecmp (tag, "jobs", MAX(taglen, 1)) == 0 ||
 
989
                 strncasecmp (tag, "jobid", MAX(taglen, 1)) == 0 ) {
 
990
                scontrol_print_job (val);
 
991
        }
 
992
        else if (strncasecmp (tag, "hostnames", MAX(taglen, 5)) == 0) {
 
993
                if (val)
 
994
                        scontrol_print_hosts(val);
 
995
                else
 
996
                        scontrol_print_hosts(getenv("SLURM_NODELIST"));
 
997
        }
 
998
        else if (strncasecmp (tag, "hostlist", MAX(taglen, 5)) == 0) {
 
999
                if (!val) {
 
1000
                        exit_code = 1;
 
1001
                        fprintf(stderr, "invalid encode argument\n");
 
1002
                        _usage();
 
1003
                } else if (scontrol_encode_hostlist(val))
 
1004
                        exit_code = 1;
 
1005
        }
 
1006
        else if (strncasecmp (tag, "nodes", MAX(taglen, 1)) == 0) {
 
1007
                scontrol_print_node_list (val);
 
1008
        }
 
1009
        else if (strncasecmp (tag, "partitions", MAX(taglen, 1)) == 0 || 
 
1010
                 strncasecmp (tag, "partitionname", MAX(taglen, 1)) == 0) {
 
1011
                scontrol_print_part (val);
 
1012
        }
 
1013
        else if (strncasecmp (tag, "reservations", MAX(taglen, 1)) == 0 || 
 
1014
                 strncasecmp (tag, "reservationname", MAX(taglen, 1)) == 0) {
 
1015
                scontrol_print_res (val);
 
1016
        }
 
1017
        else if (strncasecmp (tag, "slurmd", MAX(taglen, 2)) == 0) {
 
1018
                _print_slurmd (val);
 
1019
        }
 
1020
        else if (strncasecmp (tag, "steps", MAX(taglen, 2)) == 0) {
 
1021
                scontrol_print_step (val);
 
1022
        }
 
1023
        else if (strncasecmp (tag, "topology", MAX(taglen, 1)) == 0) {
 
1024
                scontrol_print_topo (val);
 
1025
        }
 
1026
        else {
 
1027
                exit_code = 1;
 
1028
                if (quiet_flag != 1)
 
1029
                        fprintf (stderr,
 
1030
                                 "invalid entity:%s for keyword:%s \n",
 
1031
                                 tag, argv[0]);
 
1032
        }               
 
1033
 
 
1034
}
 
1035
 
893
1036
 
894
1037
 
895
1038
/* 
901
1044
_update_it (int argc, char *argv[]) 
902
1045
{
903
1046
        int i, error_code = SLURM_SUCCESS;
 
1047
        int nodetag=0, partag=0, jobtag=0;
 
1048
        int blocktag=0, subtag=0, restag=0;
904
1049
 
905
1050
        /* First identify the entity to update */
906
1051
        for (i=0; i<argc; i++) {
907
 
                if (strncasecmp (argv[i], "NodeName=", 9) == 0) {
908
 
                        error_code = scontrol_update_node (argc, argv);
909
 
                        break;
910
 
                } else if (strncasecmp (argv[i], "PartitionName=", 14) == 0) {
911
 
                        error_code = scontrol_update_part (argc, argv);
912
 
                        break;
913
 
                } else if (strncasecmp (argv[i], "JobId=", 6) == 0) {
914
 
                        error_code = scontrol_update_job (argc, argv);
915
 
                        break;
916
 
                } else if (strncasecmp (argv[i], "BlockName=", 10) == 0) {
917
 
                        error_code = _update_bluegene_block (argc, argv);
918
 
                        break;
919
 
                } else if (strncasecmp (argv[i], "SubBPName=", 10) == 0) {
920
 
                        error_code = _update_bluegene_subbp (argc, argv);
921
 
                        break;
 
1052
                char *tag = argv[i];
 
1053
                int taglen = 0;
 
1054
                char *val = strchr(argv[i], '=');
 
1055
                if (!val)
 
1056
                        continue;
 
1057
                taglen = val - argv[i];
 
1058
                val++;
 
1059
 
 
1060
                if (strncasecmp (tag, "NodeName", MAX(taglen, 5)) == 0) {
 
1061
                        nodetag=1;
 
1062
                } else if (strncasecmp (tag, "PartitionName", MAX(taglen, 3)) == 0) {
 
1063
                        partag=1;
 
1064
                } else if (strncasecmp (tag, "JobId", MAX(taglen, 3)) == 0) {
 
1065
                        jobtag=1;
 
1066
                } else if (strncasecmp (tag, "BlockName", MAX(taglen, 3)) == 0) {
 
1067
                        blocktag=1;
 
1068
                } else if (strncasecmp (tag, "SubBPName", MAX(taglen, 3)) == 0) {
 
1069
                        subtag=1;
 
1070
                } else if (strncasecmp (tag, "ReservationName", MAX(taglen, 3)) == 0) {
 
1071
                        restag=1;
922
1072
                }
923
 
                
924
1073
        }
925
 
        
926
 
        if (i >= argc) {
 
1074
 
 
1075
        /* The order of tests matters here.  An update job request can include
 
1076
           partition and reservation tags, possibly before the jobid tag, but
 
1077
           none of the other updates have a jobid tag, so check jobtag first.
 
1078
           Likewise, check restag next, because reservations can have a 
 
1079
           partition tag.  The order of the rest doesn't matter because there
 
1080
           aren't any other duplicate tags.  */
 
1081
 
 
1082
        if (jobtag)
 
1083
                error_code = scontrol_update_job (argc, argv);
 
1084
        else if (restag)
 
1085
                error_code = scontrol_update_res (argc, argv);
 
1086
        else if (nodetag)
 
1087
                error_code = scontrol_update_node (argc, argv);
 
1088
        else if (partag)
 
1089
                error_code = scontrol_update_part (argc, argv);
 
1090
        else if (blocktag)
 
1091
                error_code = _update_bluegene_block (argc, argv);
 
1092
        else if (subtag)
 
1093
                error_code = _update_bluegene_subbp (argc, argv);
 
1094
        else {
927
1095
                exit_code = 1;
928
1096
                fprintf(stderr, "No valid entity in update command\n");
929
1097
                fprintf(stderr, "Input line must include \"NodeName\", ");
931
1099
                fprintf(stderr, "\"BlockName\", \"SubBPName\" "
932
1100
                        "(i.e. bgl000[0-3]),");
933
1101
#endif
934
 
                fprintf(stderr, "\"PartitionName\", or \"JobId\"\n");
 
1102
                fprintf(stderr, "\"PartitionName\", \"Reservation\", "
 
1103
                                "or \"JobId\"\n");
935
1104
        }
936
 
        else if (error_code) {
 
1105
 
 
1106
        if (error_code) {
937
1107
                exit_code = 1;
938
1108
                slurm_perror ("slurm_update error");
939
1109
        }
959
1129
        part_msg.hidden = (uint16_t)INFINITE;
960
1130
 
961
1131
        for (i=0; i<argc; i++) {
962
 
                if (strncasecmp(argv[i], "BlockName=", 10) == 0)
963
 
                        part_msg.name = &argv[i][10];
964
 
                else if (strncasecmp(argv[i], "State=", 6) == 0) {
965
 
                        if (strcasecmp(&argv[i][6], "ERROR") == 0)
 
1132
                char *tag = argv[i];
 
1133
                char *val = strchr(argv[i], '=');
 
1134
                int taglen = 0, vallen = 0;
 
1135
 
 
1136
                if (val) {
 
1137
                        taglen = val - argv[i];
 
1138
                        val++;
 
1139
                        vallen = strlen(val);
 
1140
                } else {
 
1141
                        exit_code = 1;
 
1142
                        error("Invalid input for BlueGene block update %s", argv[i]);
 
1143
                        return 0;
 
1144
                }
 
1145
 
 
1146
                if (strncasecmp(tag, "BlockName", MAX(taglen, 2)) == 0) {
 
1147
                        part_msg.name = val;
 
1148
                } else if (strncasecmp(tag, "State", MAX(taglen, 2)) == 0) {
 
1149
                        if (strncasecmp(val, "ERROR", MAX(vallen, 1)) == 0)
966
1150
                                part_msg.state_up = 0;
967
 
                        else if (strcasecmp(&argv[i][6], "FREE") == 0)
 
1151
                        else if (strncasecmp(val, "FREE", MAX(vallen, 1)) == 0)
968
1152
                                part_msg.state_up = 1;
969
1153
                        else {
970
1154
                                exit_code = 1;
975
1159
                                return 0;
976
1160
                        }
977
1161
                        update_cnt++;
 
1162
                } else {
 
1163
                        exit_code = 1;
 
1164
                        error("Invalid input for BlueGene block update %s", argv[i]);
 
1165
                        return 0;
978
1166
                }
979
1167
        }
 
1168
 
980
1169
        if(!part_msg.name) {
981
1170
                error("You didn't supply a name.");
982
1171
                return 0;
1012
1201
        part_msg.root_only = (uint16_t)INFINITE;
1013
1202
 
1014
1203
        for (i=0; i<argc; i++) {
1015
 
                if (strncasecmp(argv[i], "SubBPName=", 10) == 0)
1016
 
                        part_msg.name = &argv[i][10];
1017
 
                else if (strncasecmp(argv[i], "State=", 6) == 0) {
1018
 
                        if (strcasecmp(&argv[i][6], "ERROR") == 0)
 
1204
                char *tag = argv[i];
 
1205
                char *val = strchr(argv[i], '=');
 
1206
                int taglen = 0, vallen = 0;
 
1207
 
 
1208
                if (val) {
 
1209
                        taglen = val - argv[i];
 
1210
                        val++;
 
1211
                        vallen = strlen(val);
 
1212
                } else {
 
1213
                        exit_code = 1;
 
1214
                        error("Invalid input for BlueGene SubBPName update %s",
 
1215
                              argv[i]);
 
1216
                        return 0;
 
1217
                }
 
1218
 
 
1219
                if (strncasecmp(tag, "SubBPName", MAX(taglen, 2)) == 0)
 
1220
                        part_msg.name = val;
 
1221
                else if (strncasecmp(tag, "State", MAX(taglen, 2)) == 0) {
 
1222
                        if (strncasecmp(val, "ERROR", MAX(vallen, 1)) == 0)
1019
1223
                                part_msg.state_up = 0;
1020
 
                        else if (strcasecmp(&argv[i][6], "FREE") == 0)
 
1224
                        else if (strncasecmp(val, "FREE", MAX(vallen, 1)) == 0)
1021
1225
                                part_msg.state_up = 1;
1022
1226
                        else {
1023
1227
                                exit_code = 1;
1028
1232
                                return 0;
1029
1233
                        }
1030
1234
                        update_cnt++;
 
1235
                } else {
 
1236
                        exit_code = 1;
 
1237
                        error("Invalid input for BlueGene SubBPName update %s",
 
1238
                              argv[i]);
 
1239
                        return 0;
1031
1240
                }
1032
1241
        }
 
1242
 
1033
1243
        if(!part_msg.name) {
1034
1244
                error("You didn't supply a name.");
1035
1245
                return 0;
1068
1278
                              generating a core file.                      \n\
1069
1279
     all                      display information about all partitions,    \n\
1070
1280
                              including hidden partitions.                 \n\
1071
 
     checkpoint <CH_OP><step> perform a checkpoint operation on identified \n\
1072
 
                              job step \n\
 
1281
     checkpoint <CH_OP><ID>   perform a checkpoint operation on identified \n\
 
1282
                              job or job step \n\
1073
1283
     completing               display jobs in completing state along with  \n\
1074
1284
                              their completing or down nodes               \n\
1075
 
     delete <SPECIFICATIONS>  delete the specified partition, kill its jobs\n\
 
1285
     create <SPECIFICATIONS>  create a new partition or reservation        \n\
 
1286
     delete <SPECIFICATIONS>  delete the specified partition or reservation\n\
1076
1287
     exit                     terminate scontrol                           \n\
1077
1288
     help                     print this description of use.               \n\
1078
1289
     hide                     do not display information about hidden      \n\
1095
1306
     show <ENTITY> [<ID>]     display state of identified entity, default  \n\
1096
1307
                              is all records.                              \n\
1097
1308
     shutdown <OPTS>          shutdown slurm daemons                       \n\
 
1309
     takeover                 ask slurm backup controller to take over     \n\
 
1310
                              (the primary controller will be stopped)     \n\
1098
1311
     suspend <job_id>         susend specified job                         \n\
1099
1312
     resume <job_id>          resume previously suspended job              \n\
1100
 
     update <SPECIFICATIONS>  update job, node, partition, or bluegene     \n\
1101
 
                              block/subbp configuration                    \n\
 
1313
     update <SPECIFICATIONS>  update job, node, partition, reservation, or \n\
 
1314
                              bluegene block/subbp configuration           \n\
1102
1315
     verbose                  enable detailed logging.                     \n\
1103
1316
     version                  display tool version number.                 \n\
1104
1317
     !!                       Repeat the last command entered.             \n\
1105
1318
                                                                           \n\
1106
1319
  <ENTITY> may be \"config\", \"daemons\", \"job\", \"node\", \"partition\"\n\
1107
 
           \"hostlist\", \"hostnames\", \"slurmd\",                        \n\
1108
 
           (for BlueGene only: \"block\", \"subbp\" or \"step\").          \n\
 
1320
       \"reservation\", \"hostlist\", \"hostnames\", \"slurmd\",           \n\
 
1321
       \"topology\", or \"step\"                                           \n\
 
1322
       (also for BlueGene only: \"block\" or \"subbp\").                  \n\
1109
1323
                                                                           \n\
1110
1324
  <ID> may be a configuration parameter name, job id, node name, partition \n\
1111
 
       name, job step id, or hostlist or pathname to a list of host names. \n\
 
1325
       name, reservation name, job step id, or hostlist or pathname to a   \n\
 
1326
       list of host names.                                                 \n\
1112
1327
                                                                           \n\
1113
1328
  <HOSTLIST> may either be a comma separated list of host names or the     \n\
1114
1329
       absolute pathname of a file (with leading '/' containing host names \n\
1122
1337
       otherwise all slurm daemons are shutdown                            \n\
1123
1338
                                                                           \n\
1124
1339
  Node names may be specified using simple range expressions,              \n\
1125
 
  (e.g. \"lx[10-20]\" corresponsds to lx10, lx11, lx12, ...)               \n\
 
1340
  (e.g. \"lx[10-20]\" corresponds to lx10, lx11, lx12, ...)                \n\
1126
1341
  The job step id is the job id followed by a period and the step id.      \n\
1127
1342
                                                                           \n\
1128
1343
  <SPECIFICATIONS> are specified in the same format as the configuration   \n\
1133
1348
                                                                           \n\
1134
1349
  <CH_OP> identify checkpoint operations and may be \"able\", \"disable\", \n\
1135
1350
  \"enable\", \"create\", \"vacate\", \"restart\", or \"error\".           \n\
 
1351
  Additional options include \"ImageDir=<dir>\", \"MaxWait=<seconds>\" and \n\
 
1352
  \"StickToNodes\"   \n\
1136
1353
                                                                           \n\
1137
1354
  All commands and options are case-insensitive, although node names and   \n\
1138
1355
  partition names tests are case-sensitive (node names \"LX\" and \"lx\"   \n\