File: snapc_base_fns.c

package info (click to toggle)
openmpi 3.1.3-11
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 118,572 kB
  • sloc: ansic: 628,972; f90: 17,993; makefile: 13,761; sh: 7,051; java: 6,360; perl: 3,215; cpp: 2,225; python: 1,350; lex: 988; fortran: 52; tcl: 12
file content (844 lines) | stat: -rw-r--r-- 27,523 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
/*
 * Copyright (c) 2004-2010 The Trustees of Indiana University.
 *                         All rights reserved.
 * Copyright (c) 2004-2011 The Trustees of the University of Tennessee.
 *                         All rights reserved.
 * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
 *                         University of Stuttgart.  All rights reserved.
 * Copyright (c) 2004-2005 The Regents of the University of California.
 *                         All rights reserved.
 * Copyright (c) 2007      Evergrid, Inc. All rights reserved.
 * Copyright (c) 2013      Cisco Systems, Inc.  All rights reserved.
 * Copyright (c) 2014-2016 Intel, Inc.  All rights reserved.
 * $COPYRIGHT$
 *
 * Additional copyrights may follow
 *
 * $HEADER$
 */

#include "orte_config.h"

#include <string.h>
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif  /* HAVE_SYS_TYPES_H */
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif  /* HAVE_UNISTD_H */
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif /* HAVE_SYS_TYPES_H */
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif /* HAVE_SYS_STAT_H */
#ifdef HAVE_DIRENT_H
#include <dirent.h>
#endif /* HAVE_DIRENT_H */
#include <time.h>

#include "orte/mca/mca.h"
#include "opal/mca/base/base.h"

#include "opal/util/os_dirpath.h"
#include "opal/util/output.h"
#include "opal/util/show_help.h"
#include "opal/util/basename.h"
#include "opal/util/argv.h"
#include "opal/mca/crs/crs.h"
#include "opal/mca/crs/base/base.h"
#include "opal/dss/dss.h"

#include "orte/mca/rml/rml.h"
#include "orte/mca/rml/rml_types.h"
#include "orte/mca/errmgr/errmgr.h"
#include "orte/runtime/orte_globals.h"
#include "orte/util/name_fns.h"

#include "orte/mca/sstore/sstore.h"
#include "orte/mca/sstore/base/base.h"

#include "orte/mca/snapc/snapc.h"
#include "orte/mca/snapc/base/base.h"

/******************
 * Local Functions
 ******************/
size_t orte_snapc_base_snapshot_seq_number = 0;

/******************
 * Object stuff
 ******************/
OBJ_CLASS_INSTANCE(orte_snapc_base_local_snapshot_t,
                   opal_list_item_t,
                   orte_snapc_base_local_snapshot_construct,
                   orte_snapc_base_local_snapshot_destruct);

void orte_snapc_base_local_snapshot_construct(orte_snapc_base_local_snapshot_t *snapshot)
{
    snapshot->process_name.jobid  = 0;
    snapshot->process_name.vpid   = 0;

    snapshot->state = ORTE_SNAPC_CKPT_STATE_NONE;

    snapshot->ss_handle  = ORTE_SSTORE_HANDLE_INVALID;
}

void orte_snapc_base_local_snapshot_destruct( orte_snapc_base_local_snapshot_t *snapshot)
{
    snapshot->process_name.jobid  = 0;
    snapshot->process_name.vpid   = 0;

    snapshot->state = ORTE_SNAPC_CKPT_STATE_NONE;

    snapshot->ss_handle  = ORTE_SSTORE_HANDLE_INVALID;
}

/****/
OBJ_CLASS_INSTANCE(orte_snapc_base_global_snapshot_t,
                   opal_list_item_t,
                   orte_snapc_base_global_snapshot_construct,
                   orte_snapc_base_global_snapshot_destruct);

void orte_snapc_base_global_snapshot_construct(orte_snapc_base_global_snapshot_t *snapshot)
{
    OBJ_CONSTRUCT(&(snapshot->local_snapshots), opal_list_t);

    snapshot->options = OBJ_NEW(opal_crs_base_ckpt_options_t);

    snapshot->ss_handle  = ORTE_SSTORE_HANDLE_INVALID;
}

void orte_snapc_base_global_snapshot_destruct( orte_snapc_base_global_snapshot_t *snapshot)
{
    opal_list_item_t* item = NULL;

    while (NULL != (item = opal_list_remove_first(&snapshot->local_snapshots))) {
        OBJ_RELEASE(item);
    }
    OBJ_DESTRUCT(&(snapshot->local_snapshots));

    if( NULL != snapshot->options ) {
        OBJ_RELEASE(snapshot->options);
        snapshot->options = NULL;
    }

    snapshot->ss_handle  = ORTE_SSTORE_HANDLE_INVALID;
}

OBJ_CLASS_INSTANCE(orte_snapc_base_quiesce_t,
                   opal_object_t,
                   orte_snapc_base_quiesce_construct,
                   orte_snapc_base_quiesce_destruct);

void orte_snapc_base_quiesce_construct(orte_snapc_base_quiesce_t *quiesce)
{
    quiesce->epoch         = -1;
    quiesce->snapshot      = NULL;
    quiesce->ss_handle     = ORTE_SSTORE_HANDLE_INVALID;
    quiesce->ss_snapshot   = NULL;
    quiesce->handle        = NULL;
    quiesce->target_dir    = NULL;
    quiesce->crs_name      = NULL;
    quiesce->cmdline       = NULL;
    quiesce->cr_state      = OPAL_CRS_NONE;
    quiesce->checkpointing = false;
    quiesce->restarting    = false;

    quiesce->migrating     = false;
    quiesce->num_migrating = 0;
    OBJ_CONSTRUCT(&(quiesce->migrating_procs), opal_pointer_array_t);
    opal_pointer_array_init(&(quiesce->migrating_procs), 8, INT32_MAX, 8);
}

void orte_snapc_base_quiesce_destruct( orte_snapc_base_quiesce_t *quiesce)
{
    int i;
    void *item = NULL;

    quiesce->epoch = -1;

    if( NULL != quiesce->snapshot ) {
        OBJ_RELEASE(quiesce->snapshot);
        quiesce->snapshot      = NULL;
    }

    quiesce->ss_handle     = ORTE_SSTORE_HANDLE_INVALID;
    if( NULL != quiesce->ss_snapshot ) {
        OBJ_RELEASE(quiesce->ss_snapshot);
        quiesce->ss_snapshot   = NULL;
    }

    if( NULL != quiesce->handle ) {
        free(quiesce->handle);
        quiesce->handle = NULL;
    }
    if( NULL != quiesce->target_dir ) {
        free(quiesce->target_dir);
        quiesce->target_dir = NULL;
    }
    if( NULL != quiesce->crs_name ) {
        free(quiesce->crs_name);
        quiesce->crs_name = NULL;
    }
    if( NULL != quiesce->cmdline ) {
        free(quiesce->cmdline);
        quiesce->cmdline = NULL;
    }

    quiesce->cr_state      = OPAL_CRS_NONE;
    quiesce->checkpointing = false;
    quiesce->restarting    = false;

    quiesce->migrating     = false;
    quiesce->num_migrating = 0;
    for( i = 0; i < quiesce->migrating_procs.size; ++i) {
        item = opal_pointer_array_get_item(&(quiesce->migrating_procs), i);
        if( NULL != item ) {
            OBJ_RELEASE(item);
        }
    }
    OBJ_DESTRUCT(&(quiesce->migrating_procs));
}

OBJ_CLASS_INSTANCE(orte_snapc_base_request_op_t,
                   opal_object_t,
                   orte_snapc_base_request_op_construct,
                   orte_snapc_base_request_op_destruct);

void orte_snapc_base_request_op_construct(orte_snapc_base_request_op_t *op)
{
    op->event     = ORTE_SNAPC_OP_NONE;
    op->is_active = false;
    op->leader    = -1;

    op->seq_num       = -1;
    op->global_handle = NULL;
    op->ss_handle     = ORTE_SSTORE_HANDLE_INVALID;

    op->mig_num       = -1;
    op->mig_vpids     = NULL;
    /*op->mig_host_pref = NULL;*/
    op->mig_vpid_pref = NULL;
    op->mig_off_node  = NULL;
}

void orte_snapc_base_request_op_destruct( orte_snapc_base_request_op_t *op)
{
    op->event     = ORTE_SNAPC_OP_NONE;
    op->is_active = false;
    op->leader    = -1;

    op->seq_num       = -1;
    if(NULL != op->global_handle ) {
        free(op->global_handle);
        op->global_handle = NULL;
    }

    op->ss_handle     = ORTE_SSTORE_HANDLE_INVALID;

    op->mig_num       = -1;
    /*
    if( NULL != op->mig_vpids ) {
        free( op->mig_vpids );
        op->mig_vpids = NULL;
    }

    if( NULL != op->mig_host_pref ) {
        free( op->mig_host_pref );
        op->mig_host_pref = NULL;
    }

    if( NULL != op->mig_vpid_pref ) {
        free( op->mig_vpid_pref );
        op->mig_vpid_pref = NULL;
    }

    if( NULL != op->mig_off_node ) {
        free( op->mig_off_node );
        op->mig_off_node = NULL;
    }
    */
}


/***********************
 * None component stuff
 ************************/
int orte_snapc_base_none_open(void)
{
    return ORTE_SUCCESS;
}

int orte_snapc_base_none_close(void)
{
    return ORTE_SUCCESS;
}

int orte_snapc_base_none_query(mca_base_module_t **module, int *priority)
{
    *module = NULL;
    *priority = 0;

    return OPAL_SUCCESS;
}

int orte_snapc_base_module_init(bool seed, bool app)
{
    return ORTE_SUCCESS;
}

int orte_snapc_base_module_finalize(void)
{
    return ORTE_SUCCESS;
}

/* None RML command line response callback */
static void snapc_none_global_cmdline_request(int status,
                                              orte_process_name_t* sender,
                                              opal_buffer_t *buffer,
                                              orte_rml_tag_t tag,
                                              void* cbdata);
int orte_snapc_base_none_setup_job(orte_jobid_t jobid)
{

    /*
     * Coordinator command listener
     */
    orte_snapc_base_snapshot_seq_number = -1;
    orte_rml.recv_buffer_nb(ORTE_NAME_WILDCARD,
                            ORTE_RML_TAG_CKPT,
                            ORTE_RML_PERSISTENT,
                            snapc_none_global_cmdline_request,
                            NULL);

    return ORTE_SUCCESS;
}

int orte_snapc_base_none_release_job(orte_jobid_t jobid)
{
    /*
     * Remove the checkpoint request callback
     */

    return ORTE_SUCCESS;
}

int orte_snapc_base_none_ft_event(int state)
{
    return ORTE_SUCCESS;
}

int orte_snapc_base_none_start_ckpt(orte_snapc_base_quiesce_t *datum)
{
    return ORTE_SUCCESS;
}

int orte_snapc_base_none_end_ckpt(orte_snapc_base_quiesce_t *datum)
{
    return ORTE_SUCCESS;
}


/********************
 * Local Functions
 ********************/
/* None RML response callback */
static void snapc_none_global_cmdline_request(int status,
                                              orte_process_name_t* sender,
                                              opal_buffer_t *buffer,
                                              orte_rml_tag_t tag,
                                              void* cbdata)
{
    int ret;
    orte_snapc_cmd_flag_t command;
    orte_std_cntr_t n = 1;
    opal_crs_base_ckpt_options_t *options = NULL;
    orte_jobid_t jobid;

    options = OBJ_NEW(opal_crs_base_ckpt_options_t);

    n = 1;
    if (ORTE_SUCCESS != (ret = opal_dss.unpack(buffer, &command, &n, ORTE_SNAPC_CMD))) {
        ORTE_ERROR_LOG(ret);
        goto cleanup;
    }

    /*
     * orte_checkpoint has requested that a checkpoint be taken
     * Respond that a checkpoint cannot be taken at this time
     */
    if (ORTE_SNAPC_GLOBAL_INIT_CMD == command) {
        /*
         * Do the basic handshake with the orte_checkpoint command
         */
        if( ORTE_SUCCESS != (ret = orte_snapc_base_global_coord_ckpt_init_cmd(sender, buffer, options, &jobid)) ) {
            ORTE_ERROR_LOG(ret);
            goto cleanup;
        }

        /*
         * Respond with an invalid response
         */
        if( ORTE_SUCCESS != (ret = orte_snapc_base_global_coord_ckpt_update_cmd(sender, 0, ORTE_SNAPC_CKPT_STATE_NO_CKPT)) ) {
            ORTE_ERROR_LOG(ret);
            goto cleanup;
        }
    }
    /*
     * Unknown command
     */
    else {
        ORTE_ERROR_LOG(ret);
        goto cleanup;
    }

 cleanup:
    if( NULL != options ) {
        OBJ_RELEASE(options);
        options = NULL;
    }

    return;
}

/********************
 * Utility functions
 ********************/

/* Report the checkpoint status */
void orte_snapc_ckpt_state_notify(int state)
{
    switch(state) {
    case ORTE_SNAPC_CKPT_STATE_ESTABLISHED:
        opal_output(0, "%d: Checkpoint established for process %s.",
                    orte_process_info.pid, ORTE_JOBID_PRINT(ORTE_PROC_MY_NAME->jobid));
        break;
    case ORTE_SNAPC_CKPT_STATE_NO_CKPT:
        opal_output(0, "%d: Process %s is not checkpointable.",
                    orte_process_info.pid, ORTE_JOBID_PRINT(ORTE_PROC_MY_NAME->jobid));
        break;
    case ORTE_SNAPC_CKPT_STATE_ERROR:
        opal_output(0, "%d: Failed to checkpoint process %s.",
                    orte_process_info.pid, ORTE_JOBID_PRINT(ORTE_PROC_MY_NAME->jobid));
        break;
    case ORTE_SNAPC_CKPT_STATE_RECOVERED:
        opal_output(0, "%d: Successfully restarted process %s.",
                    orte_process_info.pid, ORTE_JOBID_PRINT(ORTE_PROC_MY_NAME->jobid));
        break;
    case ORTE_SNAPC_CKPT_STATE_NO_RESTART:
        opal_output(0, "%d: Failed to restart process %s.",
                    orte_process_info.pid, ORTE_JOBID_PRINT(ORTE_PROC_MY_NAME->jobid));
        break;
    /* ADK: We currently do not notify for these states, but good to
     * have them around anyways. */
    case ORTE_SNAPC_CKPT_STATE_NONE:
    case ORTE_SNAPC_CKPT_STATE_REQUEST:
    case ORTE_SNAPC_CKPT_STATE_PENDING:
    case ORTE_SNAPC_CKPT_STATE_RUNNING:
    case ORTE_SNAPC_CKPT_STATE_STOPPED:
    case ORTE_SNAPC_CKPT_STATE_MIGRATING:
    case ORTE_SNAPC_CKPT_STATE_FINISHED_LOCAL:
    default:
        break;
    }
}

int orte_snapc_base_global_coord_ckpt_init_cmd(orte_process_name_t* peer,
                                               opal_buffer_t* buffer,
                                               opal_crs_base_ckpt_options_t *options,
                                               orte_jobid_t *jobid)
{
    int ret, exit_status = ORTE_SUCCESS;
    orte_std_cntr_t count = 1;
    orte_ns_cmp_bitmask_t mask;

    mask = ORTE_NS_CMP_ALL;

    /*
     * Do not send to self, as that is silly.
     */
    if (OPAL_EQUAL ==
            orte_util_compare_name_fields(mask, peer, ORTE_PROC_MY_HNP)) {
        OPAL_OUTPUT_VERBOSE((10, orte_snapc_base_framework.framework_output,
                             "%s) base:ckpt_init_cmd: Error: Do not send to self!\n",
                             ORTE_SNAPC_COORD_NAME_PRINT(orte_snapc_coord_type)));
        return ORTE_SUCCESS;
    }

    OPAL_OUTPUT_VERBOSE((10, orte_snapc_base_framework.framework_output,
                         "%s) base:ckpt_init_cmd: Receiving commands\n",
                         ORTE_SNAPC_COORD_NAME_PRINT(orte_snapc_coord_type)));

    /********************
     * Receive command line checkpoint request:
     * - Command (already received)
     * - options
     * - jobid
     ********************/
    if( ORTE_SUCCESS != (ret = orte_snapc_base_unpack_options(buffer, options)) ) {
        opal_output(orte_snapc_base_framework.framework_output,
                    "%s) base:ckpt_init_cmd: Error: Unpack (options) Failure (ret = %d)\n",
                    ORTE_SNAPC_COORD_NAME_PRINT(orte_snapc_coord_type), ret );
        ORTE_ERROR_LOG(ret);
        exit_status = ret;
        goto cleanup;
    }

    count = 1;
    if ( ORTE_SUCCESS != (ret = opal_dss.unpack(buffer, jobid, &count, ORTE_JOBID)) ) {
        opal_output(orte_snapc_base_framework.framework_output,
                    "%s) base:ckpt_init_cmd: Error: DSS Unpack (jobid) Failure (ret = %d) (LINE = %d)\n",
                    ORTE_SNAPC_COORD_NAME_PRINT(orte_snapc_coord_type),
                    ret, __LINE__);
        ORTE_ERROR_LOG(ret);
        exit_status = ret;
        goto cleanup;
    }

    OPAL_OUTPUT_VERBOSE((10, orte_snapc_base_framework.framework_output,
                         "%s) base:ckpt_init_cmd: Received [%d, %d, %s]\n",
                         ORTE_SNAPC_COORD_NAME_PRINT(orte_snapc_coord_type),
                         (int)(options->term),
                         (int)(options->stop),
                         ORTE_JOBID_PRINT(*jobid)));

 cleanup:
    return exit_status;
}

int orte_snapc_base_unpack_options(opal_buffer_t* buffer,
                                   opal_crs_base_ckpt_options_t *options)
{
    int ret, exit_status = ORTE_SUCCESS;
    orte_std_cntr_t count = 1;

    count = 1;
    if ( ORTE_SUCCESS != (ret = opal_dss.unpack(buffer, &(options->term), &count, OPAL_BOOL)) ) {
        opal_output(orte_snapc_base_framework.framework_output,
                    "snapc:base:unpack_options: Error: Unpack (term) Failure (ret = %d)\n",
                    ret);
        ORTE_ERROR_LOG(ret);
        exit_status = ret;
        goto cleanup;
    }

    count = 1;
    if ( ORTE_SUCCESS != (ret = opal_dss.unpack(buffer, &(options->stop), &count, OPAL_BOOL)) ) {
        opal_output(orte_snapc_base_framework.framework_output,
                    "snapc:base:unpack_options: Error: Unpack (stop) Failure (ret = %d)\n",
                    ret);
        ORTE_ERROR_LOG(ret);
        exit_status = ret;
        goto cleanup;
    }

    count = 1;
    if ( ORTE_SUCCESS != (ret = opal_dss.unpack(buffer, &(options->inc_prep_only), &count, OPAL_BOOL)) ) {
        opal_output(orte_snapc_base_framework.framework_output,
                    "snapc:base:unpack_options: Error: Unpack (inc_prep_only) Failure (ret = %d)\n",
                    ret);
        ORTE_ERROR_LOG(ret);
        exit_status = ret;
        goto cleanup;
    }

    count = 1;
    if ( ORTE_SUCCESS != (ret = opal_dss.unpack(buffer, &(options->inc_recover_only), &count, OPAL_BOOL)) ) {
        opal_output(orte_snapc_base_framework.framework_output,
                    "snapc:base:unpack_options: Error: Unpack (inc_recover_only) Failure (ret = %d)\n",
                    ret);
        ORTE_ERROR_LOG(ret);
        exit_status = ret;
        goto cleanup;
    }

#if OPAL_ENABLE_CRDEBUG == 1
    count = 1;
    if ( ORTE_SUCCESS != (ret = opal_dss.unpack(buffer, &(options->attach_debugger), &count, OPAL_BOOL)) ) {
        opal_output(orte_snapc_base_framework.framework_output,
                    "snapc:base:unpack_options: Error: Unpack (attach_debugger) Failure (ret = %d)\n",
                    ret);
        ORTE_ERROR_LOG(ret);
        exit_status = ret;
        goto cleanup;
    }

    count = 1;
    if ( ORTE_SUCCESS != (ret = opal_dss.unpack(buffer, &(options->detach_debugger), &count, OPAL_BOOL)) ) {
        opal_output(orte_snapc_base_framework.framework_output,
                    "snapc:base:unpack_options: Error: Unpack (detach_debugger) Failure (ret = %d)\n",
                    ret);
        ORTE_ERROR_LOG(ret);
        exit_status = ret;
        goto cleanup;
    }
#endif

 cleanup:
    return exit_status;
}

int orte_snapc_base_pack_options(opal_buffer_t* buffer,
                                 opal_crs_base_ckpt_options_t *options)
{
    int ret, exit_status = ORTE_SUCCESS;

    if (ORTE_SUCCESS != (ret = opal_dss.pack(buffer, &(options->term), 1, OPAL_BOOL))) {
        ORTE_ERROR_LOG(ret);
        exit_status = ret;
        goto cleanup;
    }

    if (ORTE_SUCCESS != (ret = opal_dss.pack(buffer, &(options->stop), 1, OPAL_BOOL))) {
        ORTE_ERROR_LOG(ret);
        exit_status = ret;
        goto cleanup;
    }

    if (ORTE_SUCCESS != (ret = opal_dss.pack(buffer, &(options->inc_prep_only), 1, OPAL_BOOL))) {
        ORTE_ERROR_LOG(ret);
        exit_status = ret;
        goto cleanup;
    }

    if (ORTE_SUCCESS != (ret = opal_dss.pack(buffer, &(options->inc_recover_only), 1, OPAL_BOOL))) {
        ORTE_ERROR_LOG(ret);
        exit_status = ret;
        goto cleanup;
    }

#if OPAL_ENABLE_CRDEBUG == 1
    if (ORTE_SUCCESS != (ret = opal_dss.pack(buffer, &(options->attach_debugger), 1, OPAL_BOOL))) {
        ORTE_ERROR_LOG(ret);
        exit_status = ret;
        goto cleanup;
    }

    if (ORTE_SUCCESS != (ret = opal_dss.pack(buffer, &(options->detach_debugger), 1, OPAL_BOOL))) {
        ORTE_ERROR_LOG(ret);
        exit_status = ret;
        goto cleanup;
    }
#endif

 cleanup:
    return exit_status;
}

int orte_snapc_base_global_coord_ckpt_update_cmd(orte_process_name_t* peer,
                                                 orte_sstore_base_handle_t ss_handle,
                                                 int ckpt_status)
{
    int ret, exit_status = ORTE_SUCCESS;
    opal_buffer_t *loc_buffer = NULL;
    orte_snapc_cmd_flag_t command = ORTE_SNAPC_GLOBAL_UPDATE_CMD;
    char *global_snapshot_handle = NULL;
    char *tmp_str = NULL;
    int seq_num;
    orte_ns_cmp_bitmask_t mask;

    /*
     * Noop if invalid peer, or peer not specified (JJH Double check this)
     */
    if( NULL == peer ||
        OPAL_EQUAL == orte_util_compare_name_fields(ORTE_NS_CMP_ALL, ORTE_NAME_INVALID, peer) ) {
        /*return ORTE_ERR_BAD_PARAM;*/
        return ORTE_SUCCESS;
    }

    mask = ORTE_NS_CMP_ALL;

    /*
     * Do not send to self, as that is silly.
     */
    if (OPAL_EQUAL == orte_util_compare_name_fields(mask, peer, ORTE_PROC_MY_HNP)) {
        OPAL_OUTPUT_VERBOSE((10, orte_snapc_base_framework.framework_output,
                             "%s) base:ckpt_update_cmd: Error: Do not send to self!\n",
                             ORTE_SNAPC_COORD_NAME_PRINT(orte_snapc_coord_type)));
        return ORTE_SUCCESS;
    }

    /*
     * Pass on the checkpoint state.
     */
    orte_snapc_ckpt_state_notify(ckpt_status);

    OPAL_OUTPUT_VERBOSE((10, orte_snapc_base_framework.framework_output,
                         "%s) base:ckpt_update_cmd: Sending update command <status %d>\n",
                         ORTE_SNAPC_COORD_NAME_PRINT(orte_snapc_coord_type),
                         ckpt_status));

    /********************
     * Send over the status of the checkpoint
     * - ckpt_state
     * - global snapshot handle (upon finish only)
     * - sequence number        (upon finish only)
     ********************/
    if (NULL == (loc_buffer = OBJ_NEW(opal_buffer_t))) {
        exit_status = ORTE_ERROR;
        goto cleanup;
    }

    if (ORTE_SUCCESS != (ret = opal_dss.pack(loc_buffer, &command, 1, ORTE_SNAPC_CMD)) ) {
        ORTE_ERROR_LOG(ret);
        exit_status = ret;
        OBJ_RELEASE(loc_buffer);
        goto cleanup;
    }

    if (ORTE_SUCCESS != (ret = opal_dss.pack(loc_buffer, &ckpt_status, 1, OPAL_INT))) {
        opal_output(orte_snapc_base_framework.framework_output,
                    "%s) base:ckpt_update_cmd: Error: DSS Pack (ckpt_status) Failure (ret = %d) (LINE = %d)\n",
                    ORTE_SNAPC_COORD_NAME_PRINT(orte_snapc_coord_type),
                    ret, __LINE__);
        ORTE_ERROR_LOG(ret);
        exit_status = ret;
        OBJ_RELEASE(loc_buffer);
        goto cleanup;
    }

    if( ORTE_SNAPC_CKPT_STATE_RECOVERED == ckpt_status ||
        ORTE_SNAPC_CKPT_STATE_ESTABLISHED  == ckpt_status ||
        ORTE_SNAPC_CKPT_STATE_STOPPED   == ckpt_status ||
        ORTE_SNAPC_CKPT_STATE_ERROR     == ckpt_status ) {

        if( ORTE_SNAPC_CKPT_STATE_ERROR != ckpt_status ) {
            if( ORTE_SUCCESS != (ret = orte_sstore.get_attr(ss_handle,
                                                            SSTORE_METADATA_GLOBAL_SNAP_REF,
                                                            &global_snapshot_handle)) ) {
                opal_output(orte_snapc_base_framework.framework_output,
                            "%s) base:ckpt_update_cmd: Error: SStore get_attr failed (ret = %d)\n",
                            ORTE_SNAPC_COORD_NAME_PRINT(orte_snapc_coord_type), ret );
                ORTE_ERROR_LOG(ret);
                /* Do not exit here, continue so that we can inform the tool
                 * that the checkpoint has failed
                 */
            }

            if( ORTE_SUCCESS != (ret = orte_sstore.get_attr(ss_handle,
                                                            SSTORE_METADATA_GLOBAL_SNAP_SEQ,
                                                            &tmp_str)) ) {
                opal_output(orte_snapc_base_framework.framework_output,
                            "%s) base:ckpt_update_cmd: Error: SStore get_attr failed (ret = %d)\n",
                            ORTE_SNAPC_COORD_NAME_PRINT(orte_snapc_coord_type), ret );
                ORTE_ERROR_LOG(ret);
                /* Do not exit here, continue so that we can inform the tool
                 * that the checkpoint has failed
                 */
            }

            if( NULL != tmp_str ) {
                seq_num = atoi(tmp_str);
            } else {
                seq_num = -1;
            }
        } else {
            /* Checkpoint Error Case */
            global_snapshot_handle = NULL;
            seq_num = -1;
        }

        OPAL_OUTPUT_VERBOSE((10, orte_snapc_base_framework.framework_output,
                             "%s) base:ckpt_update_cmd: Sending update command <status %d> + <ref %s> <seq %d>\n",
                             ORTE_SNAPC_COORD_NAME_PRINT(orte_snapc_coord_type),
                             ckpt_status, global_snapshot_handle, seq_num));

        if (ORTE_SUCCESS != (ret = opal_dss.pack(loc_buffer, &global_snapshot_handle, 1, OPAL_STRING))) {
            opal_output(orte_snapc_base_framework.framework_output,
                        "%s) base:ckpt_update_cmd: Error: DSS Pack (snapshot handle) Failure (ret = %d) (LINE = %d)\n",
                        ORTE_SNAPC_COORD_NAME_PRINT(orte_snapc_coord_type),
                        ret, __LINE__);
            ORTE_ERROR_LOG(ret);
            exit_status = ret;
            OBJ_RELEASE(loc_buffer);
            goto cleanup;
        }

        if (ORTE_SUCCESS != (ret = opal_dss.pack(loc_buffer, &seq_num, 1, OPAL_INT))) {
            opal_output(orte_snapc_base_framework.framework_output,
                        "%s) base:ckpt_update_cmd: Error: DSS Pack (seq number) Failure (ret = %d) (LINE = %d)\n",
                        ORTE_SNAPC_COORD_NAME_PRINT(orte_snapc_coord_type),
                        ret, __LINE__);
            ORTE_ERROR_LOG(ret);
            exit_status = ret;
            OBJ_RELEASE(loc_buffer);
            goto cleanup;
        }
    }

    if (0 > (ret = orte_rml.send_buffer_nb(orte_mgmt_conduit,
                                           peer, loc_buffer,
                                           ORTE_RML_TAG_CKPT,
                                           orte_rml_send_callback, NULL))) {
        opal_output(orte_snapc_base_framework.framework_output,
                    "%s) base:ckpt_update_cmd: Error: Send (ckpt_status) Failure (ret = %d) (LINE = %d)\n",
                    ORTE_SNAPC_COORD_NAME_PRINT(orte_snapc_coord_type),
                    ret, __LINE__);
        ORTE_ERROR_LOG(ret);
        exit_status = ret;
        OBJ_RELEASE(loc_buffer);
        goto cleanup;
    }

 cleanup:
    if( NULL != global_snapshot_handle ){
        free(global_snapshot_handle);
        global_snapshot_handle = NULL;
    }
    if( NULL != tmp_str ) {
        free(tmp_str);
        tmp_str = NULL;
    }

    return exit_status;
}

/****************************
 * Command line tool request functions
 ****************************/
/* JJH TODO - Move the command line functions here ? */

/*****************************
 * Snapshot metadata functions
 *****************************/
int orte_snapc_ckpt_state_str(char ** state_str, int state)
{
    switch(state) {
    case ORTE_SNAPC_CKPT_STATE_NONE:
        *state_str = strdup(" -- ");
        break;
    case ORTE_SNAPC_CKPT_STATE_REQUEST:
        *state_str = strdup("Requested");
        break;
    case ORTE_SNAPC_CKPT_STATE_PENDING:
        *state_str = strdup("Pending");
        break;
    case ORTE_SNAPC_CKPT_STATE_RUNNING:
        *state_str = strdup("Running");
        break;
    case ORTE_SNAPC_CKPT_STATE_STOPPED:
        *state_str = strdup("Stopped");
        break;
    case ORTE_SNAPC_CKPT_STATE_MIGRATING:
        *state_str = strdup("Migrating");
        break;
    case ORTE_SNAPC_CKPT_STATE_ESTABLISHED:
        *state_str = strdup("Checkpoint Established");
        break;
    case ORTE_SNAPC_CKPT_STATE_RECOVERED:
        *state_str = strdup("Continuing/Recovered");
        break;
    case ORTE_SNAPC_CKPT_STATE_FINISHED_LOCAL:
        *state_str = strdup("Locally Finished");
        break;
    case ORTE_SNAPC_CKPT_STATE_ERROR:
        *state_str = strdup("Error");
        break;
    default:
        asprintf(state_str, "Unknown %d", state);
        break;
    }

    return ORTE_SUCCESS;
}