root/orte/mca/sstore/central/sstore_central_app.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. orte_sstore_central_app_snapshot_info_construct
  2. orte_sstore_central_app_snapshot_info_destruct
  3. orte_sstore_central_app_module_init
  4. orte_sstore_central_app_module_finalize
  5. orte_sstore_central_app_request_checkpoint_handle
  6. orte_sstore_central_app_register
  7. orte_sstore_central_app_get_attr
  8. orte_sstore_central_app_set_attr
  9. orte_sstore_central_app_sync
  10. orte_sstore_central_app_remove
  11. orte_sstore_central_app_pack
  12. orte_sstore_central_app_unpack
  13. create_new_handle_info
  14. find_handle_info
  15. pull_handle_info
  16. push_handle_info
  17. init_local_snapshot_directory
  18. metadata_open
  19. metadata_close
  20. metadata_write_str
  21. metadata_write_int
  22. metadata_write_timestamp

   1 /*
   2  * Copyright (c)      2010 The Trustees of Indiana University.
   3  *                         All rights reserved.
   4  * Copyright (c) 2018      Intel, Inc.  All rights reserved.
   5  * $COPYRIGHT$
   6  *
   7  * Additional copyrights may follow
   8  *
   9  * $HEADER$
  10  */
  11 
  12 /*
  13  *
  14  */
  15 
  16 #include "orte_config.h"
  17 
  18 #include <string.h>
  19 #include <stdlib.h>
  20 #include <sys/types.h>
  21 #include <sys/stat.h>
  22 #include <sys/wait.h>
  23 #ifdef HAVE_UNISTD_H
  24 #include <unistd.h>
  25 #endif  /* HAVE_UNISTD_H */
  26 
  27 #include "orte/mca/mca.h"
  28 #include "opal/mca/base/base.h"
  29 
  30 #include "opal/mca/event/event.h"
  31 
  32 #include "orte/constants.h"
  33 #include "orte/util/show_help.h"
  34 #include "opal/util/argv.h"
  35 #include "opal/util/output.h"
  36 #include "opal/util/show_help.h"
  37 #include "opal/util/opal_environ.h"
  38 #include "opal/util/basename.h"
  39 #include "opal/util/os_dirpath.h"
  40 
  41 #include "opal/threads/mutex.h"
  42 #include "opal/threads/condition.h"
  43 
  44 #include "orte/util/name_fns.h"
  45 #include "orte/util/proc_info.h"
  46 #include "orte/runtime/orte_globals.h"
  47 #include "orte/runtime/orte_wait.h"
  48 #include "orte/mca/errmgr/errmgr.h"
  49 #include "orte/mca/rml/rml.h"
  50 #include "orte/mca/rml/rml_types.h"
  51 
  52 #include "orte/mca/sstore/sstore.h"
  53 #include "orte/mca/sstore/base/base.h"
  54 
  55 #include "sstore_central.h"
  56 
  57 /**********
  58  * Object stuff
  59  **********/
  60 struct  orte_sstore_central_app_snapshot_info_t {
  61     /** List super object */
  62     opal_list_item_t super;
  63 
  64     /** */
  65     orte_sstore_base_handle_t id;
  66 
  67     /** Global Sequence Number */
  68     int seq_num;
  69 
  70     /** Global Reference Name */
  71     char * global_ref_name;
  72 
  73     /** Local Location (Absolute Path) */
  74     char * local_location;
  75 
  76     /** Metadata File Name (Absolute Path) */
  77     char *metadata_filename;
  78 
  79     /** Metadata File Descriptor */
  80     FILE *metadata;
  81 
  82     /** CRS Component used */
  83     char * crs_comp;
  84 
  85     /** Did this process skip the checkpoint? */
  86     bool ckpt_skipped;
  87 };
  88 typedef struct orte_sstore_central_app_snapshot_info_t orte_sstore_central_app_snapshot_info_t;
  89 ORTE_DECLSPEC OBJ_CLASS_DECLARATION(orte_sstore_central_app_snapshot_info_t);
  90 
  91 void orte_sstore_central_app_snapshot_info_construct(orte_sstore_central_app_snapshot_info_t *info);
  92 void orte_sstore_central_app_snapshot_info_destruct( orte_sstore_central_app_snapshot_info_t *info);
  93 
  94 OBJ_CLASS_INSTANCE(orte_sstore_central_app_snapshot_info_t,
  95                    opal_list_item_t,
  96                    orte_sstore_central_app_snapshot_info_construct,
  97                    orte_sstore_central_app_snapshot_info_destruct);
  98 
  99 
 100 /**********
 101  * Local Function and Variable Declarations
 102  **********/
 103 static orte_sstore_central_app_snapshot_info_t *create_new_handle_info(orte_sstore_base_handle_t handle);
 104 static orte_sstore_central_app_snapshot_info_t *find_handle_info(orte_sstore_base_handle_t handle);
 105 
 106 static int init_local_snapshot_directory(orte_sstore_central_app_snapshot_info_t *handle_info);
 107 static int pull_handle_info(orte_sstore_central_app_snapshot_info_t *handle_info );
 108 static int push_handle_info(orte_sstore_central_app_snapshot_info_t *handle_info );
 109 
 110 static int metadata_open(orte_sstore_central_app_snapshot_info_t * handle_info);
 111 static int metadata_close(orte_sstore_central_app_snapshot_info_t * handle_info);
 112 static int metadata_write_str(orte_sstore_central_app_snapshot_info_t * handle_info, char * key, char *value);
 113 static int metadata_write_int(orte_sstore_central_app_snapshot_info_t * handle_info, char *key, int value);
 114 static int metadata_write_timestamp(orte_sstore_central_app_snapshot_info_t * handle_info);
 115 
 116 static opal_list_t *active_handles = NULL;
 117 
 118 /**********
 119  * Object stuff
 120  **********/
 121 void orte_sstore_central_app_snapshot_info_construct(orte_sstore_central_app_snapshot_info_t *info)
 122 {
 123     info->id      = 0;
 124 
 125     info->seq_num = -1;
 126 
 127     info->global_ref_name = NULL;
 128     info->local_location  = NULL;
 129 
 130     info->metadata_filename = NULL;
 131     info->metadata = NULL;
 132 
 133     info->crs_comp = NULL;
 134 
 135     info->ckpt_skipped = false;
 136 }
 137 
 138 void orte_sstore_central_app_snapshot_info_destruct( orte_sstore_central_app_snapshot_info_t *info)
 139 {
 140     info->id      = 0;
 141     info->seq_num = -1;
 142 
 143     if( NULL != info->global_ref_name ) {
 144         free( info->global_ref_name );
 145         info->global_ref_name  = NULL;
 146     }
 147 
 148     if( NULL != info->local_location ) {
 149         free( info->local_location );
 150         info->local_location = NULL;
 151     }
 152 
 153     if( NULL != info->metadata_filename ) {
 154         free( info->metadata_filename ) ;
 155         info->metadata_filename = NULL;
 156     }
 157 
 158     if( NULL != info->metadata ) {
 159         fclose(info->metadata);
 160         info->metadata = NULL;
 161     }
 162 
 163     if( NULL != info->crs_comp ) {
 164         free( info->crs_comp );
 165         info->crs_comp = NULL;
 166     }
 167 
 168     info->ckpt_skipped = false;
 169 }
 170 
 171 /******************
 172  * Local functions
 173  ******************/
 174 int orte_sstore_central_app_module_init(void)
 175 {
 176     if( NULL == active_handles ) {
 177         active_handles = OBJ_NEW(opal_list_t);
 178     }
 179 
 180     return ORTE_SUCCESS;
 181 }
 182 
 183 int orte_sstore_central_app_module_finalize(void)
 184 {
 185     if( NULL != active_handles ) {
 186         OBJ_RELEASE(active_handles);
 187     }
 188 
 189     return ORTE_SUCCESS;
 190 }
 191 
 192 int orte_sstore_central_app_request_checkpoint_handle(orte_sstore_base_handle_t *handle, int seq, orte_jobid_t jobid)
 193 {
 194     opal_output(0, "sstore:central:(app): request_checkpoint_handle() Not implemented!");
 195     return ORTE_ERR_NOT_IMPLEMENTED;
 196 }
 197 
 198 int orte_sstore_central_app_register(orte_sstore_base_handle_t handle)
 199 {
 200     int ret, exit_status = ORTE_SUCCESS;
 201     orte_sstore_central_app_snapshot_info_t *handle_info = NULL;
 202 
 203     OPAL_OUTPUT_VERBOSE((10, mca_sstore_central_component.super.output_handle,
 204                          "sstore:central:(app): register(%d)", (int)handle));
 205 
 206     /*
 207      * Create a handle
 208      */
 209     orte_sstore_handle_current = handle;
 210     handle_info = find_handle_info(handle);
 211     if( NULL != handle_info ) {
 212         /* Remove the old, stale handle */
 213         opal_list_remove_item(active_handles, &(handle_info->super));
 214     }
 215     handle_info = create_new_handle_info(handle);
 216 
 217     /*
 218      * Get basic information from Local SStore
 219      */
 220     if( ORTE_SUCCESS != (ret = pull_handle_info(handle_info)) ) {
 221         ORTE_ERROR_LOG(ret);
 222         exit_status = ret;
 223         goto cleanup;
 224     }
 225 
 226     /*
 227      * Setup the storage directory
 228      */
 229     if( ORTE_SUCCESS != (ret = init_local_snapshot_directory(handle_info)) ) {
 230         ORTE_ERROR_LOG(ret);
 231         exit_status = ret;
 232         goto cleanup;
 233     }
 234 
 235  cleanup:
 236     return exit_status;
 237 }
 238 
 239 int orte_sstore_central_app_get_attr(orte_sstore_base_handle_t handle, orte_sstore_base_key_t key, char **value)
 240 {
 241     int exit_status = ORTE_SUCCESS;
 242     orte_sstore_central_app_snapshot_info_t *handle_info = NULL;
 243 
 244     OPAL_OUTPUT_VERBOSE((10, mca_sstore_central_component.super.output_handle,
 245                          "sstore:central:(app): get_attr(%d)", key));
 246 
 247     /*
 248      * Lookup the handle
 249      */
 250     handle_info = find_handle_info(handle);
 251 
 252     /*
 253      * Access metadata
 254      */
 255     if( SSTORE_METADATA_GLOBAL_SNAP_SEQ == key ) {
 256         opal_asprintf(value, "%d", handle_info->seq_num);
 257         OPAL_OUTPUT_VERBOSE((10, mca_sstore_central_component.super.output_handle,
 258                              "sstore:central:(app): get_attr(%d, %d) Seq = <%s>", key, handle_info->id, *value));
 259     }
 260     else if( SSTORE_METADATA_LOCAL_SNAP_LOC == key) {
 261         *value = strdup(handle_info->local_location);
 262     }
 263     else if( SSTORE_METADATA_LOCAL_SNAP_META == key ) {
 264         *value = strdup(handle_info->metadata_filename);
 265     }
 266     else if( SSTORE_METADATA_GLOBAL_SNAP_REF == key ) {
 267         *value = strdup(handle_info->global_ref_name);
 268         OPAL_OUTPUT_VERBOSE((10, mca_sstore_central_component.super.output_handle,
 269                              "sstore:central:(app): get_attr(%d, %d) Ref = <%s>", key, handle_info->id, *value));
 270     }
 271     else {
 272         exit_status = ORTE_ERR_NOT_SUPPORTED;
 273         goto cleanup;
 274     }
 275 
 276     OPAL_OUTPUT_VERBOSE((10, mca_sstore_central_component.super.output_handle,
 277                          "sstore:central:(app): get_attr(%d, %d) <%s>", key, handle_info->id, *value));
 278  cleanup:
 279     return exit_status;
 280 }
 281 
 282 int orte_sstore_central_app_set_attr(orte_sstore_base_handle_t handle, orte_sstore_base_key_t key, char *value)
 283 {
 284     int ret, exit_status = ORTE_SUCCESS;
 285     orte_sstore_central_app_snapshot_info_t *handle_info = NULL;
 286     char *key_str = NULL;
 287 
 288     OPAL_OUTPUT_VERBOSE((10, mca_sstore_central_component.super.output_handle,
 289                          "sstore:central:(app): set_attr(%d = %s)", key, value));
 290 
 291     if( NULL == value ) {
 292         ORTE_ERROR_LOG(ORTE_ERROR);
 293         exit_status = ORTE_ERROR;
 294         goto cleanup;
 295     }
 296 
 297     if( key >= SSTORE_METADATA_MAX ) {
 298         ORTE_ERROR_LOG(ORTE_ERROR);
 299         exit_status = ORTE_ERROR;
 300         goto cleanup;
 301     }
 302 
 303     /*
 304      * Lookup the handle
 305      */
 306     handle_info = find_handle_info(handle);
 307 
 308     /*
 309      * Access metadata
 310      */
 311     if( SSTORE_METADATA_LOCAL_CRS_COMP == key ) {
 312         if( NULL != handle_info->crs_comp ) {
 313             free(handle_info->crs_comp);
 314         }
 315         handle_info->crs_comp = strdup(value);
 316     }
 317     else if(SSTORE_METADATA_LOCAL_SKIP_CKPT == key ) {
 318         handle_info->ckpt_skipped = true;
 319     }
 320     else if( SSTORE_METADATA_LOCAL_MKDIR == key ||
 321              SSTORE_METADATA_LOCAL_TOUCH == key ) {
 322         orte_sstore_base_convert_key_to_string(key, &key_str);
 323         if( ORTE_SUCCESS != (ret = metadata_write_str(handle_info, key_str, value))) {
 324             ORTE_ERROR_LOG(ret);
 325             exit_status = ret;
 326             goto cleanup;
 327         }
 328     }
 329     else {
 330         exit_status = ORTE_ERROR;
 331         goto cleanup;
 332     }
 333 
 334  cleanup:
 335     if( NULL != key_str ) {
 336         free(key_str);
 337         key_str = NULL;
 338     }
 339 
 340     return exit_status;
 341 }
 342 
 343 int orte_sstore_central_app_sync(orte_sstore_base_handle_t handle)
 344 {
 345     int ret, exit_status = ORTE_SUCCESS;
 346     orte_sstore_central_app_snapshot_info_t *handle_info = NULL;
 347 
 348     OPAL_OUTPUT_VERBOSE((10, mca_sstore_central_component.super.output_handle,
 349                          "sstore:central:(app): sync()"));
 350 
 351     /*
 352      * Lookup the handle
 353      */
 354     handle_info = find_handle_info(handle);
 355 
 356     /*
 357      * Finalize and close the metadata
 358      */
 359     if( ORTE_SUCCESS != (ret = metadata_write_timestamp(handle_info)) ) {
 360         ORTE_ERROR_LOG(ret);
 361         exit_status = ret;
 362         goto cleanup;
 363     }
 364 
 365     if( ORTE_SUCCESS != (ret = metadata_close(handle_info)) ) {
 366         ORTE_ERROR_LOG(ret);
 367         exit_status = ret;
 368         goto cleanup;
 369     }
 370 
 371     /*
 372      * Push information to the Local coordinator
 373      */
 374     if( ORTE_SUCCESS != (ret = push_handle_info(handle_info)) ) {
 375         ORTE_ERROR_LOG(ret);
 376         exit_status = ret;
 377         goto cleanup;
 378     }
 379 
 380  cleanup:
 381     orte_sstore_handle_current = ORTE_SSTORE_HANDLE_INVALID;
 382 
 383     return exit_status;
 384 }
 385 
 386 int orte_sstore_central_app_remove(orte_sstore_base_handle_t handle)
 387 {
 388     opal_output(0, "sstore:central:(app): remove() Not implemented!");
 389     return ORTE_ERR_NOT_IMPLEMENTED;
 390 }
 391 
 392 int orte_sstore_central_app_pack(orte_process_name_t* peer, opal_buffer_t* buffer, orte_sstore_base_handle_t handle)
 393 {
 394     opal_output(0, "sstore:central:(app): pack() Not implemented!");
 395     return ORTE_ERR_NOT_IMPLEMENTED;
 396 }
 397 
 398 int orte_sstore_central_app_unpack(orte_process_name_t* peer, opal_buffer_t* buffer, orte_sstore_base_handle_t *handle)
 399 {
 400     opal_output(0, "sstore:central:(app): unpack() Not implemented!");
 401     return ORTE_ERR_NOT_IMPLEMENTED;
 402 }
 403 
 404 /**************************
 405  * Local functions
 406  **************************/
 407 static orte_sstore_central_app_snapshot_info_t *create_new_handle_info(orte_sstore_base_handle_t handle)
 408 {
 409     orte_sstore_central_app_snapshot_info_t *handle_info = NULL;
 410 
 411     handle_info = OBJ_NEW(orte_sstore_central_app_snapshot_info_t);
 412 
 413     handle_info->id = handle;
 414 
 415     opal_list_append(active_handles, &(handle_info->super));
 416 
 417     return handle_info;
 418 }
 419 
 420 static orte_sstore_central_app_snapshot_info_t *find_handle_info(orte_sstore_base_handle_t handle)
 421 {
 422     orte_sstore_central_app_snapshot_info_t *handle_info = NULL;
 423     opal_list_item_t* item = NULL;
 424 
 425     for(item  = opal_list_get_first(active_handles);
 426         item != opal_list_get_end(active_handles);
 427         item  = opal_list_get_next(item) ) {
 428         handle_info = (orte_sstore_central_app_snapshot_info_t*)item;
 429 
 430         if( handle_info->id == handle ) {
 431             return handle_info;
 432         }
 433     }
 434 
 435     return NULL;
 436 }
 437 
 438 static int pull_handle_info(orte_sstore_central_app_snapshot_info_t *handle_info )
 439 {
 440     int ret, exit_status = ORTE_SUCCESS;
 441     opal_buffer_t *buffer = NULL;
 442     orte_sstore_central_cmd_flag_t command;
 443     orte_std_cntr_t count;
 444     orte_sstore_base_handle_t loc_id;
 445     orte_rml_recv_cb_t* rb = NULL;
 446 
 447     buffer = OBJ_NEW(opal_buffer_t);
 448 
 449     /*
 450      * Ask the daemon to send us the info that we need
 451      */
 452     command = ORTE_SSTORE_CENTRAL_PULL;
 453     if (ORTE_SUCCESS != (ret = opal_dss.pack(buffer, &command, 1, ORTE_SSTORE_CENTRAL_CMD))) {
 454         ORTE_ERROR_LOG(ret);
 455         exit_status = ret;
 456         goto cleanup;
 457     }
 458 
 459     if (ORTE_SUCCESS != (ret = opal_dss.pack(buffer, &(handle_info->id), 1, ORTE_SSTORE_HANDLE))) {
 460         ORTE_ERROR_LOG(ret);
 461         exit_status = ret;
 462         goto cleanup;
 463     }
 464 
 465     if (ORTE_SUCCESS != (ret = orte_rml.send_buffer_nb(ORTE_PROC_MY_DAEMON, buffer,
 466                                                        ORTE_RML_TAG_SSTORE_INTERNAL,
 467                                                        orte_rml_send_callback, NULL))) {
 468         ORTE_ERROR_LOG(ret);
 469         exit_status = ret;
 470         goto cleanup;
 471     }
 472 
 473     /* buffer should not be released here; the callback releases it */
 474     buffer = NULL;
 475 
 476     /*
 477      * Receive the response
 478      */
 479     OPAL_OUTPUT_VERBOSE((10, mca_sstore_central_component.super.output_handle,
 480                          "sstore:central:(app): pull() from %s -> %s",
 481                          ORTE_NAME_PRINT(ORTE_PROC_MY_NAME),
 482                          ORTE_NAME_PRINT(ORTE_PROC_MY_DAEMON)));
 483 
 484     rb = OBJ_NEW(orte_rml_recv_cb_t);
 485     rb->active = true;
 486     orte_rml.recv_buffer_nb(ORTE_PROC_MY_DAEMON, ORTE_RML_TAG_SSTORE_INTERNAL,
 487                             0, orte_rml_recv_callback, rb);
 488     ORTE_WAIT_FOR_COMPLETION(rb->active);
 489 
 490     count = 1;
 491     if (ORTE_SUCCESS != (ret = opal_dss.unpack(&rb->data, &command, &count, ORTE_SSTORE_CENTRAL_CMD))) {
 492         ORTE_ERROR_LOG(ret);
 493         exit_status = ret;
 494         goto cleanup;
 495     }
 496 
 497     count = 1;
 498     if (ORTE_SUCCESS != (ret = opal_dss.unpack(&rb->data, &loc_id, &count, ORTE_SSTORE_HANDLE))) {
 499         ORTE_ERROR_LOG(ret);
 500         exit_status = ret;
 501         goto cleanup;
 502     }
 503     if( loc_id != handle_info->id ) {
 504         ; /* JJH Big problem */
 505     }
 506 
 507     count = 1;
 508     if (ORTE_SUCCESS != (ret = opal_dss.unpack(&rb->data, &(handle_info->seq_num), &count, OPAL_INT))) {
 509         ORTE_ERROR_LOG(ret);
 510         exit_status = ret;
 511         goto cleanup;
 512     }
 513 
 514     count = 1;
 515     if (ORTE_SUCCESS != (ret = opal_dss.unpack(&rb->data, &(handle_info->global_ref_name), &count, OPAL_STRING))) {
 516         ORTE_ERROR_LOG(ret);
 517         exit_status = ret;
 518         goto cleanup;
 519     }
 520 
 521     count = 1;
 522     if (ORTE_SUCCESS != (ret = opal_dss.unpack(&rb->data, &(handle_info->local_location), &count, OPAL_STRING))) {
 523         ORTE_ERROR_LOG(ret);
 524         exit_status = ret;
 525         goto cleanup;
 526     }
 527 
 528     count = 1;
 529     if (ORTE_SUCCESS != (ret = opal_dss.unpack(&rb->data, &(handle_info->metadata_filename), &count, OPAL_STRING))) {
 530         ORTE_ERROR_LOG(ret);
 531         exit_status = ret;
 532         goto cleanup;
 533     }
 534 
 535     OPAL_OUTPUT_VERBOSE((10, mca_sstore_central_component.super.output_handle,
 536                          "sstore:central:(app): pull() from %s -> %s (%d, %d, %s)",
 537                          ORTE_NAME_PRINT(ORTE_PROC_MY_NAME),
 538                          ORTE_NAME_PRINT(ORTE_PROC_MY_DAEMON),
 539                          handle_info->id,
 540                          handle_info->seq_num,
 541                          handle_info->global_ref_name
 542                          ));
 543  cleanup:
 544     if (NULL != buffer) {
 545         OBJ_RELEASE(buffer);
 546         buffer = NULL;
 547     }
 548     if (NULL != rb) {
 549         OBJ_RELEASE(rb);
 550         buffer = NULL;
 551     }
 552 
 553     return exit_status;
 554 }
 555 
 556 static int push_handle_info(orte_sstore_central_app_snapshot_info_t *handle_info )
 557 {
 558     int ret, exit_status = ORTE_SUCCESS;
 559     opal_buffer_t *buffer = NULL;
 560     orte_sstore_central_cmd_flag_t command;
 561 
 562     buffer = OBJ_NEW(opal_buffer_t);
 563 
 564     command = ORTE_SSTORE_CENTRAL_PUSH;
 565     if (ORTE_SUCCESS != (ret = opal_dss.pack(buffer, &command, 1, ORTE_SSTORE_CENTRAL_CMD))) {
 566         ORTE_ERROR_LOG(ret);
 567         exit_status = ret;
 568         goto cleanup;
 569     }
 570 
 571     if (ORTE_SUCCESS != (ret = opal_dss.pack(buffer, &(handle_info->id), 1, ORTE_SSTORE_HANDLE))) {
 572         ORTE_ERROR_LOG(ret);
 573         exit_status = ret;
 574         goto cleanup;
 575     }
 576 
 577     if (ORTE_SUCCESS != (ret = opal_dss.pack(buffer, &(handle_info->ckpt_skipped), 1, OPAL_BOOL))) {
 578         ORTE_ERROR_LOG(ret);
 579         exit_status = ret;
 580         goto cleanup;
 581     }
 582 
 583     if( !handle_info->ckpt_skipped ) {
 584         if (ORTE_SUCCESS != (ret = opal_dss.pack(buffer, &(handle_info->crs_comp), 1, OPAL_STRING))) {
 585             ORTE_ERROR_LOG(ret);
 586             exit_status = ret;
 587             goto cleanup;
 588         }
 589     }
 590 
 591     if (ORTE_SUCCESS != (ret = orte_rml.send_buffer_nb(ORTE_PROC_MY_DAEMON, buffer,
 592                                                        ORTE_RML_TAG_SSTORE_INTERNAL,
 593                                                        orte_rml_send_callback, NULL))) {
 594         ORTE_ERROR_LOG(ret);
 595         exit_status = ret;
 596         goto cleanup;
 597     }
 598 
 599     /* buffer should not be released here; the callback releases it */
 600     buffer = NULL;
 601 
 602  cleanup:
 603     if (NULL != buffer) {
 604         OBJ_RELEASE(buffer);
 605         buffer = NULL;
 606     }
 607 
 608     return exit_status;
 609 }
 610 
 611 static int init_local_snapshot_directory(orte_sstore_central_app_snapshot_info_t *handle_info)
 612 {
 613     int ret, exit_status = ORTE_SUCCESS;
 614     mode_t my_mode = S_IRWXU;
 615 
 616     /*
 617      * Make the snapshot directory from the uniq_global_snapshot_name
 618      */
 619     if(OPAL_SUCCESS != (ret = opal_os_dirpath_create(handle_info->local_location, my_mode)) ) {
 620         opal_show_help("help-orte-sstore-central.txt", "fail_path_create", true,
 621                        ORTE_NAME_PRINT(ORTE_PROC_MY_NAME),
 622                        orte_process_info.nodename,
 623                        handle_info->local_location);
 624         ORTE_ERROR_LOG(ret);
 625         exit_status = ret;
 626         goto cleanup;
 627     }
 628 
 629     /*
 630      * Open up the metadata file
 631      */
 632     if( ORTE_SUCCESS != (ret = metadata_open(handle_info)) ) {
 633         ORTE_ERROR_LOG(ret);
 634         exit_status = ret;
 635         goto cleanup;
 636     }
 637 
 638     /*
 639      * Add a timestamp and the PID of this process
 640      */
 641     if( ORTE_SUCCESS != (ret = metadata_write_timestamp(handle_info)) ) {
 642         ORTE_ERROR_LOG(ret);
 643         exit_status = ret;
 644         goto cleanup;
 645     }
 646 
 647     if( ORTE_SUCCESS != (ret = metadata_write_int(handle_info, SSTORE_METADATA_LOCAL_PID_STR, (int)getpid())) ) {
 648         ORTE_ERROR_LOG(ret);
 649         exit_status = ret;
 650         goto cleanup;
 651     }
 652 
 653     if( ORTE_SUCCESS != (ret = metadata_close(handle_info)) ) {
 654         ORTE_ERROR_LOG(ret);
 655         exit_status = ret;
 656         goto cleanup;
 657     }
 658 
 659  cleanup:
 660     return exit_status;
 661 }
 662 
 663 
 664 /**************************
 665  * Metadata functions
 666  **************************/
 667 static int metadata_open(orte_sstore_central_app_snapshot_info_t * handle_info)
 668 {
 669     /* If already open, then just return */
 670     if( NULL != handle_info->metadata ) {
 671         return ORTE_SUCCESS;
 672     }
 673 
 674     if (NULL == (handle_info->metadata = fopen(handle_info->metadata_filename, "a")) ) {
 675         opal_output(orte_sstore_base_framework.framework_output,
 676                     "sstore:central:(global):init_dir() Unable to open the file (%s)\n",
 677                     handle_info->metadata_filename);
 678         ORTE_ERROR_LOG(ORTE_ERROR);
 679         return ORTE_ERROR;
 680    }
 681 
 682    return ORTE_SUCCESS;
 683 }
 684 
 685 static int metadata_close(orte_sstore_central_app_snapshot_info_t * handle_info)
 686 {
 687     /* If already closed, then just return */
 688     if( NULL == handle_info->metadata ) {
 689         return ORTE_SUCCESS;
 690     }
 691 
 692     fclose(handle_info->metadata);
 693     handle_info->metadata = NULL;
 694 
 695     return ORTE_SUCCESS;
 696 }
 697 
 698 static int metadata_write_str(orte_sstore_central_app_snapshot_info_t * handle_info, char *key, char *value)
 699 {
 700     int ret, exit_status = ORTE_SUCCESS;
 701 
 702     /* Make sure the metadata file is open */
 703     if( NULL == handle_info->metadata ) {
 704         if( ORTE_SUCCESS != (ret = metadata_open(handle_info)) ) {
 705             ORTE_ERROR_LOG(ret);
 706             exit_status = ret;
 707             goto cleanup;
 708         }
 709     }
 710 
 711     fprintf(handle_info->metadata, "%s%s\n", key, value);
 712 
 713  cleanup:
 714     /* Must close the metadata each time, since if we try to checkpoint the
 715      * CRS might want to restore the FD, and will likely fail if the snapshot
 716      * moved */
 717     if( NULL != handle_info->metadata ) {
 718         fclose(handle_info->metadata);
 719         handle_info->metadata = NULL;
 720     }
 721 
 722     return exit_status;
 723 }
 724 
 725 static int metadata_write_int(orte_sstore_central_app_snapshot_info_t * handle_info, char *key, int value)
 726 {
 727     int ret, exit_status = ORTE_SUCCESS;
 728 
 729     /* Make sure the metadata file is open */
 730     if( NULL == handle_info->metadata ) {
 731         if( ORTE_SUCCESS != (ret = metadata_open(handle_info)) ) {
 732             ORTE_ERROR_LOG(ret);
 733             exit_status = ret;
 734             goto cleanup;
 735         }
 736     }
 737 
 738     fprintf(handle_info->metadata, "%s%d\n", key, value);
 739 
 740  cleanup:
 741     return exit_status;
 742 }
 743 
 744 static int metadata_write_timestamp(orte_sstore_central_app_snapshot_info_t * handle_info)
 745 {
 746     int ret, exit_status = ORTE_SUCCESS;
 747     time_t timestamp;
 748 
 749     /* Make sure the metadata file is open */
 750     if( NULL == handle_info->metadata ) {
 751         if( ORTE_SUCCESS != (ret = metadata_open(handle_info)) ) {
 752             ORTE_ERROR_LOG(ret);
 753             exit_status = ret;
 754             goto cleanup;
 755         }
 756     }
 757 
 758     timestamp = time(NULL);
 759     fprintf(handle_info->metadata, "%s%s", SSTORE_METADATA_INTERNAL_TIME_STR, ctime(&timestamp));
 760 
 761  cleanup:
 762     return exit_status;
 763 }

/* [<][>][^][v][top][bottom][index][help] */