root/branches/cu-security-branch/src/apps/admin/pvfs2-check-config.c @ 8397

Revision 8397, 5.8 KB (checked in by nlmills, 3 years ago)

initial merge with Orange-Branch. much will be broken

Line 
1/*
2 * (C) 2001 Clemson University and The University of Chicago
3 *
4 * See COPYING in top-level directory.
5 */
6
7#include <unistd.h>
8#include <stdio.h>
9#include <errno.h>
10#include <string.h>
11#include <sys/types.h>
12#include <sys/stat.h>
13#include <fcntl.h>
14#include <sys/time.h>
15#include <time.h>
16#include <stdlib.h>
17
18#include "client-state-machine.h"
19#include "pint-sysint-utils.h"
20#include "pvfs2.h"
21#include "pvfs2-mgmt.h"
22#include "server-config.h"
23
24
25/**
26 * Print out usage information
27 */
28static void print_usage(int argc, char** argv)
29{
30    printf("Usage: %s\n", argv[0]);
31    return;
32}
33
34/**
35 * Compare the copy configuration to the master.  Return 0 if the configs are
36 * the same, else non-zero.
37 *
38 * Currently implemented as a white space insensitive byte comparison.
39 */
40static int compare_configs(const char* master_config,
41                           const char* config)
42{
43    printf("Config: %s", master_config);
44    printf("\n");
45    return 1;
46}
47
48/**
49 * Populate the given config with the server's data
50 */
51static int get_config(PVFS_BMI_addr_t* server_addr,
52                      struct PVFS_sys_mntent* mnt_entry,
53                      char** fs_config_buf,
54                      char** server_config_buf)
55{
56#if 0
57/*
58  FIXME: this breaks the intended sysint usage -- rewrite using the
59  sysint calls, rather than the internals of; find a better way to
60  'persist' the configs, or work it into the exposed api
61*/
62    int rc;
63    PINT_client_sm* sm_p = NULL;
64    PVFS_credentials creds;
65
66    /* Retrieve credentials */
67    PVFS_util_gen_credentials(&creds);
68   
69    /* Initialize the state machine */
70    sm_p = malloc(sizeof(*sm_p));
71    memset(sm_p, 0, sizeof(*sm_p));
72    sm_p->cred_p = &creds;
73    sm_p->msgarray_count = 1;
74    sm_p->msgarray = &(sm_p->msgpair);
75    sm_p->u.get_config.mntent = mnt_entry;
76    sm_p->u.get_config.persist_config_buffers = 1;
77
78    /* Get the config info */
79    rc = PINT_client_state_machine_post(sm_p, PVFS_SERVER_GET_CONFIG);
80    while (!sm_p->op_complete && (0 == rc))
81    {
82        rc = PINT_client_state_machine_test();
83    }
84
85    if (0 != rc)
86    {
87        fprintf(stderr, "Error occured while getting config.\n");
88        return -1;
89    }
90
91    /* Copy the strings into outbound params */
92    *fs_config_buf = malloc(sm_p->u.get_config.fs_config_buf_size + 1);
93    *server_config_buf = malloc(sm_p->u.get_config.server_config_buf_size + 1);
94    strncpy(*fs_config_buf,
95            sm_p->u.get_config.fs_config_buf,
96            sm_p->u.get_config.fs_config_buf_size + 1);
97    strncpy(*server_config_buf,
98            sm_p->u.get_config.server_config_buf,
99            sm_p->u.get_config.server_config_buf_size + 1);
100
101    /* Free state machine resources */
102    free(sm_p->u.get_config.fs_config_buf);
103    free(sm_p->u.get_config.server_config_buf);
104    free(sm_p);
105#endif   
106    return 0;       
107}
108
109/**
110 * Main
111 */
112int main(int argc, char **argv)
113{
114    const PVFS_util_tab* mnt;
115    int rc;
116
117    /* Ensure no arguments were passed */
118    if (1 < argc)
119    {
120        print_usage(argc, argv);
121        return -1;
122    }
123   
124    /* Initialize the PVFS System */
125    rc = PVFS_sys_initialize(GOSSIP_NO_DEBUG);
126    if (0 != rc)
127    {
128        fprintf(stderr, "Unable to initialize PVFS\n");
129        return -1;
130    }
131
132    /* Construct the list of mount points */
133    mnt = PVFS_util_parse_pvfstab(0);
134    if (0 != mnt)
135    {
136        int num_mnt_entries = 0, i = 0;
137
138        /* Iterate over all fsid's */
139        num_mnt_entries = mnt->mntent_count;
140        for (i = 0; i < num_mnt_entries; ++i)
141        {
142            PVFS_fs_id fs_id;
143            PVFS_BMI_addr_t* server_addrs;
144            int server_count;
145            char* master_fs_conf = 0;
146            int j;
147
148            /* Current fs id */
149            rc = PVFS_sys_fs_add(&mnt->mntent_array[i]);
150            if (0 != rc)
151            {
152                fprintf(stderr, "Unable to initialize target filesystem.\n");
153                continue;
154            }
155            fs_id = mnt->mntent_array[i].fs_id;
156           
157            /* Retrieve the list of all servers for the fs id*/
158            rc = PVFS_mgmt_count_servers(fs_id, PVFS_MGMT_IO_SERVER,
159                                         &server_count);
160
161            if (0 != rc)
162            {
163                fprintf(stderr, "Unable to determine number of IO servers.\n");
164                break;
165            }
166            server_addrs = malloc(server_count * sizeof(PVFS_BMI_addr_t));
167            rc = PVFS_mgmt_get_server_array(fs_id, PVFS_MGMT_IO_SERVER,
168                                            server_addrs, &server_count);
169            if (0 != rc)
170            {
171                fprintf(stderr, "Unable to retrieve array of server addrs.\n");
172                break;
173            }
174           
175            /* Get the server configs for each fs id */
176            for (j = 0; j < server_count; j++)
177            {
178                char* fs_config_buf = 0;
179                char* server_config_buf = 0;
180               
181                rc = get_config(server_addrs + j,
182                                mnt->mntent_array + i,
183                                &fs_config_buf,
184                                &server_config_buf);
185
186                if (0 != rc)
187                {
188                    fprintf(stderr, "No config for server, continuing.\n");
189                    continue;
190                }
191
192                if (0 == j)
193                {
194                    master_fs_conf = fs_config_buf;
195
196                    /* Compare config to the master config */
197                    compare_configs(master_fs_conf, fs_config_buf);
198                }
199                else
200                {
201                    /* Compare config to the master config */
202                    compare_configs(master_fs_conf, fs_config_buf);
203                }
204            }
205        }
206    }   
207
208    printf("Check Complete.\n");
209    return 0;
210}
211
212/*
213 * Local variables:
214 *  c-indent-level: 4
215 *  c-basic-offset: 4
216 * End:
217 *
218 * vim: ts=8 sts=4 sw=4 expandtab
219 */
Note: See TracBrowser for help on using the browser.