root/orte/mca/sstore/stage/sstore_stage_app.c

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

DEFINITIONS

This source file includes following definitions.
  1. orte_sstore_stage_app_snapshot_info_construct
  2. orte_sstore_stage_app_snapshot_info_destruct
  3. orte_sstore_stage_app_module_init
  4. orte_sstore_stage_app_module_finalize
  5. orte_sstore_stage_app_request_checkpoint_handle
  6. orte_sstore_stage_app_register
  7. orte_sstore_stage_app_get_attr
  8. orte_sstore_stage_app_set_attr
  9. orte_sstore_stage_app_sync
  10. orte_sstore_stage_app_remove
  11. orte_sstore_stage_app_pack
  12. orte_sstore_stage_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_stage.h"
  56 
  57 /**********
  58  * Object stuff
  59  **********/
  60 struct  orte_sstore_stage_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_stage_app_snapshot_info_t orte_sstore_stage_app_snapshot_info_t;
  89 ORTE_DECLSPEC OBJ_CLASS_DECLARATION(orte_sstore_stage_app_snapshot_info_t);
  90 
  91 void orte_sstore_stage_app_snapshot_info_construct(orte_sstore_stage_app_snapshot_info_t *info);
  92 void orte_sstore_stage_app_snapshot_info_destruct( orte_sstore_stage_app_snapshot_info_t *info);
  93 
  94 OBJ_CLASS_INSTANCE(orte_sstore_stage_app_snapshot_info_t,
  95                    opal_list_item_t,
  96                    orte_sstore_stage_app_snapshot_info_construct,
  97                    orte_sstore_stage_app_snapshot_info_destruct);
  98 
  99 
 100 /**********
 101  * Local Function and Variable Declarations
 102  **********/
 103 static orte_sstore_stage_app_snapshot_info_t *create_new_handle_info(orte_sstore_base_handle_t handle);
 104 static orte_sstore_stage_app_snapshot_info_t *find_handle_info(orte_sstore_base_handle_t handle);
 105 
 106 static int init_local_snapshot_directory(orte_sstore_stage_app_snapshot_info_t *handle_info);
 107 static int pull_handle_info(orte_sstore_stage_app_snapshot_info_t *handle_info );
 108 static int push_handle_info(orte_sstore_stage_app_snapshot_info_t *handle_info );
 109 
 110 static int metadata_open(orte_sstore_stage_app_snapshot_info_t * handle_info);
 111 static int metadata_close(orte_sstore_stage_app_snapshot_info_t * handle_info);
 112 static int metadata_write_str(orte_sstore_stage_app_snapshot_info_t * handle_info, char * key, char *value);
 113 static int metadata_write_int(orte_sstore_stage_app_snapshot_info_t * handle_info, char *key, int value);
 114 static int metadata_write_timestamp(orte_sstore_stage_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_stage_app_snapshot_info_construct(orte_sstore_stage_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_stage_app_snapshot_info_destruct( orte_sstore_stage_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_stage_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_stage_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_stage_app_request_checkpoint_handle(orte_sstore_base_handle_t *handle, int seq, orte_jobid_t jobid)
 193 {
 194     opal_output(0, "sstore:stage:(app): request_checkpoint_handle() Not implemented!");
 195     return ORTE_ERR_NOT_IMPLEMENTED;
 196 }
 197 
 198 int orte_sstore_stage_app_register(orte_sstore_base_handle_t handle)
 199 {
 200     int ret, exit_status = ORTE_SUCCESS;
 201     orte_sstore_stage_app_snapshot_info_t *handle_info = NULL;
 202 
 203     OPAL_OUTPUT_VERBOSE((10, mca_sstore_stage_component.super.output_handle,
 204                          "sstore:stage:(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_stage_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_stage_app_snapshot_info_t *handle_info = NULL;
 243 
 244     OPAL_OUTPUT_VERBOSE((10, mca_sstore_stage_component.super.output_handle,
 245                          "sstore:stage:(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     }
 258     else if( SSTORE_METADATA_LOCAL_SNAP_LOC == key) {
 259         *value = strdup(handle_info->local_location);
 260     }
 261     else if( SSTORE_METADATA_LOCAL_SNAP_META == key ) {
 262         *value = strdup(handle_info->metadata_filename);
 263     }
 264     else if( SSTORE_METADATA_GLOBAL_SNAP_REF == key ) {
 265         *value = strdup(handle_info->global_ref_name);
 266     }
 267     else {
 268         exit_status = ORTE_ERR_NOT_SUPPORTED;
 269         goto cleanup;
 270     }
 271 
 272  cleanup:
 273     return exit_status;
 274 }
 275 
 276 int orte_sstore_stage_app_set_attr(orte_sstore_base_handle_t handle, orte_sstore_base_key_t key, char *value)
 277 {
 278     int ret, exit_status = ORTE_SUCCESS;
 279     orte_sstore_stage_app_snapshot_info_t *handle_info = NULL;
 280     char *key_str = NULL;
 281 
 282     OPAL_OUTPUT_VERBOSE((10, mca_sstore_stage_component.super.output_handle,
 283                          "sstore:stage:(app): set_attr(%d = %s)", key, value));
 284 
 285     if( NULL == value ) {
 286         ORTE_ERROR_LOG(ORTE_ERROR);
 287         exit_status = ORTE_ERROR;
 288         goto cleanup;
 289     }
 290 
 291     if( key >= SSTORE_METADATA_MAX ) {
 292         ORTE_ERROR_LOG(ORTE_ERROR);
 293         exit_status = ORTE_ERROR;
 294         goto cleanup;
 295     }
 296 
 297     /*
 298      * Lookup the handle
 299      */
 300     handle_info = find_handle_info(handle);
 301 
 302     /*
 303      * Access metadata
 304      */
 305     if( SSTORE_METADATA_LOCAL_CRS_COMP == key ) {
 306         if( NULL != handle_info->crs_comp ) {
 307             free(handle_info->crs_comp);
 308         }
 309         handle_info->crs_comp = strdup(value);
 310     }
 311     else if(SSTORE_METADATA_LOCAL_SKIP_CKPT == key ) {
 312         handle_info->ckpt_skipped = true;
 313     }
 314     else if( SSTORE_METADATA_LOCAL_MKDIR == key ||
 315              SSTORE_METADATA_LOCAL_TOUCH == key ) {
 316         orte_sstore_base_convert_key_to_string(key, &key_str);
 317         if( ORTE_SUCCESS != (ret = metadata_write_str(handle_info, key_str, value))) {
 318             ORTE_ERROR_LOG(ret);
 319             exit_status = ret;
 320             goto cleanup;
 321         }
 322     }
 323     else {
 324         exit_status = ORTE_ERROR;
 325         goto cleanup;
 326     }
 327 
 328  cleanup:
 329     return exit_status;
 330 }
 331 
 332 int orte_sstore_stage_app_sync(orte_sstore_base_handle_t handle)
 333 {
 334     int ret, exit_status = ORTE_SUCCESS;
 335     orte_sstore_stage_app_snapshot_info_t *handle_info = NULL;
 336 
 337     OPAL_OUTPUT_VERBOSE((10, mca_sstore_stage_component.super.output_handle,
 338                          "sstore:stage:(app): sync()"));
 339 
 340     /*
 341      * Lookup the handle
 342      */
 343     handle_info = find_handle_info(handle);
 344 
 345     /*
 346      * Finalize and close the metadata
 347      */
 348     if( ORTE_SUCCESS != (ret = metadata_write_timestamp(handle_info)) ) {
 349         ORTE_ERROR_LOG(ret);
 350         exit_status = ret;
 351         goto cleanup;
 352     }
 353 
 354     if( ORTE_SUCCESS != (ret = metadata_close(handle_info)) ) {
 355         ORTE_ERROR_LOG(ret);
 356         exit_status = ret;
 357         goto cleanup;
 358     }
 359 
 360     /*
 361      * Push information to the Local coordinator
 362      */
 363     if( ORTE_SUCCESS != (ret = push_handle_info(handle_info)) ) {
 364         ORTE_ERROR_LOG(ret);
 365         exit_status = ret;
 366         goto cleanup;
 367     }
 368 
 369  cleanup:
 370     orte_sstore_handle_current = ORTE_SSTORE_HANDLE_INVALID;
 371 
 372     return exit_status;
 373 }
 374 
 375 int orte_sstore_stage_app_remove(orte_sstore_base_handle_t handle)
 376 {
 377     opal_output(0, "sstore:stage:(app): remove() Not implemented!");
 378     return ORTE_ERR_NOT_IMPLEMENTED;
 379 }
 380 
 381 int orte_sstore_stage_app_pack(orte_process_name_t* peer, opal_buffer_t* buffer, orte_sstore_base_handle_t handle)
 382 {
 383     opal_output(0, "sstore:stage:(app): pack() Not implemented!");
 384     return ORTE_ERR_NOT_IMPLEMENTED;
 385 }
 386 
 387 int orte_sstore_stage_app_unpack(orte_process_name_t* peer, opal_buffer_t* buffer, orte_sstore_base_handle_t *handle)
 388 {
 389     opal_output(0, "sstore:stage:(app): unpack() Not implemented!");
 390     return ORTE_ERR_NOT_IMPLEMENTED;
 391 }
 392 
 393 /**************************
 394  * Local functions
 395  **************************/
 396 static orte_sstore_stage_app_snapshot_info_t *create_new_handle_info(orte_sstore_base_handle_t handle)
 397 {
 398     orte_sstore_stage_app_snapshot_info_t *handle_info = NULL;
 399 
 400     handle_info = OBJ_NEW(orte_sstore_stage_app_snapshot_info_t);
 401 
 402     handle_info->id = handle;
 403 
 404     opal_list_append(active_handles, &(handle_info->super));
 405 
 406     return handle_info;
 407 }
 408 
 409 static orte_sstore_stage_app_snapshot_info_t *find_handle_info(orte_sstore_base_handle_t handle)
 410 {
 411     orte_sstore_stage_app_snapshot_info_t *handle_info = NULL;
 412     opal_list_item_t* item = NULL;
 413 
 414     for(item  = opal_list_get_first(active_handles);
 415         item != opal_list_get_end(active_handles);
 416         item  = opal_list_get_next(item) ) {
 417         handle_info = (orte_sstore_stage_app_snapshot_info_t*)item;
 418 
 419         if( handle_info->id == handle ) {
 420             return handle_info;
 421         }
 422     }
 423 
 424     return NULL;
 425 }
 426 
 427 static int pull_handle_info(orte_sstore_stage_app_snapshot_info_t *handle_info )
 428 {
 429     int ret, exit_status = ORTE_SUCCESS;
 430     opal_buffer_t *buffer = NULL;
 431     orte_sstore_stage_cmd_flag_t command;
 432     orte_std_cntr_t count;
 433     orte_sstore_base_handle_t loc_id;
 434     orte_rml_recv_cb_t *rb = NULL;
 435 
 436     buffer = OBJ_NEW(opal_buffer_t);
 437 
 438     /*
 439      * Ask the daemon to send us the info that we need
 440      */
 441     command = ORTE_SSTORE_STAGE_PULL;
 442     if (ORTE_SUCCESS != (ret = opal_dss.pack(buffer, &command, 1, ORTE_SSTORE_STAGE_CMD))) {
 443         ORTE_ERROR_LOG(ret);
 444         exit_status = ret;
 445         goto cleanup;
 446     }
 447 
 448     if (ORTE_SUCCESS != (ret = opal_dss.pack(buffer, &(handle_info->id), 1, ORTE_SSTORE_HANDLE))) {
 449         ORTE_ERROR_LOG(ret);
 450         exit_status = ret;
 451         goto cleanup;
 452     }
 453 
 454     if (ORTE_SUCCESS != (ret = orte_rml.send_buffer_nb(ORTE_PROC_MY_DAEMON, buffer,
 455                                                        ORTE_RML_TAG_SSTORE_INTERNAL,
 456                                                        orte_rml_send_callback, NULL))) {
 457         ORTE_ERROR_LOG(ret);
 458         exit_status = ret;
 459         goto cleanup;
 460     }
 461 
 462     /* buffer should not be released here; the callback releases it */
 463     buffer = NULL;
 464 
 465     /*
 466      * Receive the response
 467      */
 468     OPAL_OUTPUT_VERBOSE((10, mca_sstore_stage_component.super.output_handle,
 469                          "sstore:stage:(app): pull() from %s -> %s",
 470                          ORTE_NAME_PRINT(ORTE_PROC_MY_NAME),
 471                          ORTE_NAME_PRINT(ORTE_PROC_MY_DAEMON)));
 472 
 473     rb = OBJ_NEW(orte_rml_recv_cb_t);
 474     rb->active = true;
 475     orte_rml.recv_buffer_nb(ORTE_PROC_MY_DAEMON, ORTE_RML_TAG_SSTORE_INTERNAL,
 476                             0, orte_rml_recv_callback, rb);
 477     ORTE_WAIT_FOR_COMPLETION(rb->active);
 478 
 479     count = 1;
 480     if (ORTE_SUCCESS != (ret = opal_dss.unpack(&rb->data, &command, &count, ORTE_SSTORE_STAGE_CMD))) {
 481         ORTE_ERROR_LOG(ret);
 482         exit_status = ret;
 483         goto cleanup;
 484     }
 485 
 486     count = 1;
 487     if (ORTE_SUCCESS != (ret = opal_dss.unpack(&rb->data, &loc_id, &count, ORTE_SSTORE_HANDLE))) {
 488         ORTE_ERROR_LOG(ret);
 489         exit_status = ret;
 490         goto cleanup;
 491     }
 492     if( loc_id != handle_info->id ) {
 493         ; /* JJH Big problem */
 494     }
 495 
 496     count = 1;
 497     if (ORTE_SUCCESS != (ret = opal_dss.unpack(&rb->data, &(handle_info->seq_num), &count, OPAL_INT))) {
 498         ORTE_ERROR_LOG(ret);
 499         exit_status = ret;
 500         goto cleanup;
 501     }
 502 
 503     count = 1;
 504     if (ORTE_SUCCESS != (ret = opal_dss.unpack(&rb->data, &(handle_info->global_ref_name), &count, OPAL_STRING))) {
 505         ORTE_ERROR_LOG(ret);
 506         exit_status = ret;
 507         goto cleanup;
 508     }
 509 
 510     count = 1;
 511     if (ORTE_SUCCESS != (ret = opal_dss.unpack(&rb->data, &(handle_info->local_location), &count, OPAL_STRING))) {
 512         ORTE_ERROR_LOG(ret);
 513         exit_status = ret;
 514         goto cleanup;
 515     }
 516 
 517     count = 1;
 518     if (ORTE_SUCCESS != (ret = opal_dss.unpack(&rb->data, &(handle_info->metadata_filename), &count, OPAL_STRING))) {
 519         ORTE_ERROR_LOG(ret);
 520         exit_status = ret;
 521         goto cleanup;
 522     }
 523 
 524  cleanup:
 525     if (NULL != buffer) {
 526         OBJ_RELEASE(buffer);
 527         buffer = NULL;
 528     }
 529     if (NULL != rb) {
 530         OBJ_RELEASE(rb);
 531         buffer = NULL;
 532     }
 533 
 534     return exit_status;
 535 }
 536 
 537 static int push_handle_info(orte_sstore_stage_app_snapshot_info_t *handle_info )
 538 {
 539     int ret, exit_status = ORTE_SUCCESS;
 540     opal_buffer_t *buffer = NULL;
 541     orte_sstore_stage_cmd_flag_t command;
 542 
 543     buffer = OBJ_NEW(opal_buffer_t);
 544 
 545     command = ORTE_SSTORE_STAGE_PUSH;
 546     if (ORTE_SUCCESS != (ret = opal_dss.pack(buffer, &command, 1, ORTE_SSTORE_STAGE_CMD))) {
 547         ORTE_ERROR_LOG(ret);
 548         exit_status = ret;
 549         goto cleanup;
 550     }
 551 
 552     if (ORTE_SUCCESS != (ret = opal_dss.pack(buffer, &(handle_info->id), 1, ORTE_SSTORE_HANDLE))) {
 553         ORTE_ERROR_LOG(ret);
 554         exit_status = ret;
 555         goto cleanup;
 556     }
 557 
 558     if (ORTE_SUCCESS != (ret = opal_dss.pack(buffer, &(handle_info->ckpt_skipped), 1, OPAL_BOOL))) {
 559         ORTE_ERROR_LOG(ret);
 560         exit_status = ret;
 561         goto cleanup;
 562     }
 563 
 564     if( !handle_info->ckpt_skipped ) {
 565         if (ORTE_SUCCESS != (ret = opal_dss.pack(buffer, &(handle_info->crs_comp), 1, OPAL_STRING))) {
 566             ORTE_ERROR_LOG(ret);
 567             exit_status = ret;
 568             goto cleanup;
 569         }
 570     }
 571 
 572     if (ORTE_SUCCESS != (ret = orte_rml.send_buffer_nb(ORTE_PROC_MY_DAEMON, buffer,
 573                                                        ORTE_RML_TAG_SSTORE_INTERNAL,
 574                                                        orte_rml_send_callback, NULL))) {
 575         ORTE_ERROR_LOG(ret);
 576         exit_status = ret;
 577         goto cleanup;
 578     }
 579     /* buffer should not be released here; the callback releases it */
 580     buffer = NULL;
 581 
 582  cleanup:
 583     if (NULL != buffer) {
 584         OBJ_RELEASE(buffer);
 585         buffer = NULL;
 586     }
 587 
 588     return exit_status;
 589 }
 590 
 591 static int init_local_snapshot_directory(orte_sstore_stage_app_snapshot_info_t *handle_info)
 592 {
 593     int ret, exit_status = ORTE_SUCCESS;
 594     mode_t my_mode = S_IRWXU;
 595 
 596     /*
 597      * Make the snapshot directory from the uniq_global_snapshot_name
 598      */
 599     if(OPAL_SUCCESS != (ret = opal_os_dirpath_create(handle_info->local_location, my_mode)) ) {
 600         opal_show_help("help-orte-sstore-stage.txt", "fail_path_create", true,
 601                        ORTE_NAME_PRINT(ORTE_PROC_MY_NAME),
 602                        orte_process_info.nodename,
 603                        handle_info->local_location);
 604         ORTE_ERROR_LOG(ret);
 605         exit_status = ret;
 606         goto cleanup;
 607     }
 608 
 609     /*
 610      * Open up the metadata file
 611      */
 612     if( ORTE_SUCCESS != (ret = metadata_open(handle_info)) ) {
 613         ORTE_ERROR_LOG(ret);
 614         exit_status = ret;
 615         goto cleanup;
 616     }
 617 
 618     /*
 619      * Add a timestamp and the PID of this process
 620      */
 621     if( ORTE_SUCCESS != (ret = metadata_write_timestamp(handle_info)) ) {
 622         ORTE_ERROR_LOG(ret);
 623         exit_status = ret;
 624         goto cleanup;
 625     }
 626 
 627     if( ORTE_SUCCESS != (ret = metadata_write_int(handle_info, SSTORE_METADATA_LOCAL_PID_STR, (int)getpid())) ) {
 628         ORTE_ERROR_LOG(ret);
 629         exit_status = ret;
 630         goto cleanup;
 631     }
 632 
 633     if( ORTE_SUCCESS != (ret = metadata_close(handle_info)) ) {
 634         ORTE_ERROR_LOG(ret);
 635         exit_status = ret;
 636         goto cleanup;
 637     }
 638 
 639  cleanup:
 640     return exit_status;
 641 }
 642 
 643 
 644 /**************************
 645  * Metadata functions
 646  **************************/
 647 static int metadata_open(orte_sstore_stage_app_snapshot_info_t * handle_info)
 648 {
 649     /* If already open, then just return */
 650     if( NULL != handle_info->metadata ) {
 651         return ORTE_SUCCESS;
 652     }
 653 
 654     if (NULL == (handle_info->metadata = fopen(handle_info->metadata_filename, "a")) ) {
 655         opal_output(orte_sstore_base_framework.framework_output,
 656                     "sstore:stage:(global):init_dir() Unable to open the file (%s)\n",
 657                     handle_info->metadata_filename);
 658         ORTE_ERROR_LOG(ORTE_ERROR);
 659         return ORTE_ERROR;
 660    }
 661 
 662    return ORTE_SUCCESS;
 663 }
 664 
 665 static int metadata_close(orte_sstore_stage_app_snapshot_info_t * handle_info)
 666 {
 667     /* If already closed, then just return */
 668     if( NULL == handle_info->metadata ) {
 669         return ORTE_SUCCESS;
 670     }
 671 
 672     fclose(handle_info->metadata);
 673     handle_info->metadata = NULL;
 674 
 675     return ORTE_SUCCESS;
 676 }
 677 
 678 static int metadata_write_str(orte_sstore_stage_app_snapshot_info_t * handle_info, char *key, char *value)
 679 {
 680     int ret, exit_status = ORTE_SUCCESS;
 681 
 682     /* Make sure the metadata file is open */
 683     if( NULL == handle_info->metadata ) {
 684         if( ORTE_SUCCESS != (ret = metadata_open(handle_info)) ) {
 685             ORTE_ERROR_LOG(ret);
 686             exit_status = ret;
 687             goto cleanup;
 688         }
 689     }
 690 
 691     fprintf(handle_info->metadata, "%s%s\n", key, value);
 692 
 693  cleanup:
 694     /* Must close the metadata each time, since if we try to checkpoint the
 695      * CRS might want to restore the FD, and will likely fail if the snapshot
 696      * moved */
 697     if( NULL != handle_info->metadata ) {
 698         fclose(handle_info->metadata);
 699         handle_info->metadata = NULL;
 700     }
 701 
 702     return exit_status;
 703 }
 704 
 705 static int metadata_write_int(orte_sstore_stage_app_snapshot_info_t * handle_info, char *key, int value)
 706 {
 707     int ret, exit_status = ORTE_SUCCESS;
 708 
 709     /* Make sure the metadata file is open */
 710     if( NULL == handle_info->metadata ) {
 711         if( ORTE_SUCCESS != (ret = metadata_open(handle_info)) ) {
 712             ORTE_ERROR_LOG(ret);
 713             exit_status = ret;
 714             goto cleanup;
 715         }
 716     }
 717 
 718     fprintf(handle_info->metadata, "%s%d\n", key, value);
 719 
 720  cleanup:
 721     return exit_status;
 722 }
 723 
 724 static int metadata_write_timestamp(orte_sstore_stage_app_snapshot_info_t * handle_info)
 725 {
 726     int ret, exit_status = ORTE_SUCCESS;
 727     time_t timestamp;
 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     timestamp = time(NULL);
 739     fprintf(handle_info->metadata, "%s%s", SSTORE_METADATA_INTERNAL_TIME_STR, ctime(&timestamp));
 740 
 741  cleanup:
 742     return exit_status;
 743 }

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