1 /*
2  * Copyright (c) 2012-2013 Los Alamos National Security, Inc.  All rights reserved.
3  * Copyright (c) 2013      Intel, Inc. All rights reserved
4  * Copyright (c) 2014      Research Organization for Information Science
5  *                         and Technology (RIST). All rights reserved.
6  * $COPYRIGHT$
7  *
8  * Additional copyrights may follow
9  *
10  * $HEADER$
11  */
12 
13 
14 #include "orte_config.h"
15 #include "orte/constants.h"
16 
17 #include <string.h>
18 #ifdef HAVE_UNISTD_H
19 #include <unistd.h>
20 #endif
21 #ifdef HAVE_SYS_TYPES_H
22 #include <sys/types.h>
23 #endif
24 
25 #include "orte/mca/mca.h"
26 #include "opal/mca/base/base.h"
27 
28 #include "opal/util/opal_environ.h"
29 #include "opal/util/output.h"
30 
31 #include "orte/util/show_help.h"
32 #include "orte/mca/dfs/base/base.h"
33 
34 #include "orte/mca/dfs/base/static-components.h"
35 
36 /*
37  * Globals
38  */
39 orte_dfs_base_module_t orte_dfs = {
40     NULL,
41     NULL,
42     NULL,
43     NULL,
44     NULL,
45     NULL,
46     NULL,
47     NULL,
48     NULL,
49     NULL,
50     NULL
51 };
52 
orte_dfs_base_close(void)53 static int orte_dfs_base_close(void)
54 {
55     /* Close selected component */
56     if (NULL != orte_dfs.finalize) {
57         orte_dfs.finalize();
58     }
59 
60     return mca_base_framework_components_close(&orte_dfs_base_framework, NULL);
61 }
62 
63 /**
64  * Function for finding and opening either all MCA components, or the one
65  * that was specifically requested via a MCA parameter.
66  */
orte_dfs_base_open(mca_base_open_flag_t flags)67 static int orte_dfs_base_open(mca_base_open_flag_t flags)
68 {
69     /* Open up all available components */
70     return mca_base_framework_components_open(&orte_dfs_base_framework, flags);
71 }
72 
73 MCA_BASE_FRAMEWORK_DECLARE(orte, dfs, "ORTE Distributed File System",
74                            NULL, orte_dfs_base_open, orte_dfs_base_close,
75                            mca_dfs_base_static_components, 0);
76 
77 
78 /* instantiate classes */
trk_con(orte_dfs_tracker_t * trk)79 static void trk_con(orte_dfs_tracker_t *trk)
80 {
81     trk->host_daemon.jobid = ORTE_JOBID_INVALID;
82     trk->host_daemon.vpid = ORTE_VPID_INVALID;
83     trk->uri = NULL;
84     trk->scheme = NULL;
85     trk->filename = NULL;
86     trk->location = 0;
87 }
trk_des(orte_dfs_tracker_t * trk)88 static void trk_des(orte_dfs_tracker_t *trk)
89 {
90     if (NULL != trk->uri) {
91         free(trk->uri);
92     }
93     if (NULL != trk->scheme) {
94         free(trk->scheme);
95     }
96     if (NULL != trk->filename) {
97         free(trk->filename);
98     }
99 }
100 OBJ_CLASS_INSTANCE(orte_dfs_tracker_t,
101                    opal_list_item_t,
102                    trk_con, trk_des);
req_const(orte_dfs_request_t * dfs)103 static void req_const(orte_dfs_request_t *dfs)
104 {
105     dfs->id = 0;
106     dfs->uri = NULL;
107     dfs->local_fd = -1;
108     dfs->remote_fd = -1;
109     dfs->read_length = -1;
110     dfs->bptr = NULL;
111     OBJ_CONSTRUCT(&dfs->bucket, opal_buffer_t);
112     dfs->read_buffer = NULL;
113     dfs->open_cbfunc = NULL;
114     dfs->close_cbfunc = NULL;
115     dfs->size_cbfunc = NULL;
116     dfs->seek_cbfunc = NULL;
117     dfs->read_cbfunc = NULL;
118     dfs->post_cbfunc = NULL;
119     dfs->fm_cbfunc = NULL;
120     dfs->load_cbfunc = NULL;
121     dfs->purge_cbfunc = NULL;
122     dfs->cbdata = NULL;
123 }
req_dest(orte_dfs_request_t * dfs)124 static void req_dest(orte_dfs_request_t *dfs)
125 {
126     if (NULL != dfs->uri) {
127         free(dfs->uri);
128     }
129     OBJ_DESTRUCT(&dfs->bucket);
130 }
131 OBJ_CLASS_INSTANCE(orte_dfs_request_t,
132                    opal_list_item_t,
133                    req_const, req_dest);
134 
jobfm_const(orte_dfs_jobfm_t * fm)135 static void jobfm_const(orte_dfs_jobfm_t *fm)
136 {
137     OBJ_CONSTRUCT(&fm->maps, opal_list_t);
138 }
jobfm_dest(orte_dfs_jobfm_t * fm)139 static void jobfm_dest(orte_dfs_jobfm_t *fm)
140 {
141     opal_list_item_t *item;
142 
143     while (NULL != (item = opal_list_remove_first(&fm->maps))) {
144         OBJ_RELEASE(item);
145     }
146     OBJ_DESTRUCT(&fm->maps);
147 }
148 OBJ_CLASS_INSTANCE(orte_dfs_jobfm_t,
149                    opal_list_item_t,
150                    jobfm_const, jobfm_dest);
151 
vpidfm_const(orte_dfs_vpidfm_t * fm)152 static void vpidfm_const(orte_dfs_vpidfm_t *fm)
153 {
154     OBJ_CONSTRUCT(&fm->data, opal_buffer_t);
155     fm->num_entries = 0;
156 }
vpidfm_dest(orte_dfs_vpidfm_t * fm)157 static void vpidfm_dest(orte_dfs_vpidfm_t *fm)
158 {
159     OBJ_DESTRUCT(&fm->data);
160 }
161 OBJ_CLASS_INSTANCE(orte_dfs_vpidfm_t,
162                    opal_list_item_t,
163                    vpidfm_const, vpidfm_dest);
164