summaryrefslogtreecommitdiffstats
path: root/xlators/mgmt/glusterd/src/glusterd-ha.c
blob: 26de16b3a7ae1973d827379764498f1062cc717b (plain)
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
/*
  Copyright (c) 2007-2010 Gluster, Inc. <http://www.gluster.com>
  This file is part of GlusterFS.

  GlusterFS is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published
  by the Free Software Foundation; either version 3 of the License,
  or (at your option) any later version.

  GlusterFS is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see
  <http://www.gnu.org/licenses/>.
*/
#ifndef _CONFIG_H
#define _CONFIG_H
#include "config.h"
#endif
#include <inttypes.h>


#include "globals.h"
#include "glusterfs.h"
#include "compat.h"
#include "dict.h"
#include "protocol-common.h"
//#include "transport.h"
#include "xlator.h"
#include "logging.h"
#include "timer.h"
#include "defaults.h"
#include "compat.h"
#include "compat-errno.h"
#include "statedump.h"
#include "glusterd-mem-types.h"
#include "glusterd.h"
#include "glusterd-sm.h"
#include "glusterd-op-sm.h"
#include "glusterd-utils.h"
#include "glusterd-ha.h"
#include "gd-xdr.h"
#include "cli-xdr.h"
#include "rpc-clnt.h"

#include <sys/resource.h>
#include <inttypes.h>

int32_t
glusterd_ha_create_volume (glusterd_volinfo_t *volinfo)
{
        char    pathname[PATH_MAX] = {0,};
        int32_t ret = -1;
        char    filepath[PATH_MAX] = {0,};
        char    buf[4096] = {0,};
        int     fd = -1;

        GF_ASSERT (volinfo);
        snprintf (pathname, 1024, "%s/vols/%s", GLUSTERD_DEFAULT_WORKDIR,
                  volinfo->volname);

        ret = mkdir (pathname, 0x777);

        if (-1 == ret) {
                gf_log ("", GF_LOG_ERROR, "mkdir() failed on path %s,"
                        "errno: %d", pathname, errno);
                goto out;
        }

        snprintf (filepath, 1024, "%s/info", pathname);

        fd = open (filepath, O_RDWR | O_CREAT | O_APPEND, 0644);

        if (-1 == fd) {
                gf_log ("", GF_LOG_ERROR, "open() failed on path %s,"
                        "errno: %d", filepath, errno);
                ret = -1;
                goto out;
        }

        snprintf (buf, 4096, "type=%d\n", volinfo->type);
        ret = write (fd, buf, strlen (buf));
        snprintf (buf, 4096, "count=%d\n", volinfo->brick_count);
        ret = write (fd, buf, strlen (buf));
        close (fd);

        ret = 0;

out:
        if (ret) {
                glusterd_ha_delete_volume (volinfo);
        }

        gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);

        return ret;
}


int32_t
glusterd_ha_delete_volume (glusterd_volinfo_t *volinfo)
{
        char    pathname[PATH_MAX] = {0,};
        int32_t ret = -1;
        char    filepath[PATH_MAX] = {0,};

        GF_ASSERT (volinfo);
        snprintf (pathname, 1024, "%s/vols/%s", GLUSTERD_DEFAULT_WORKDIR,
                  volinfo->volname);

        snprintf (filepath, 1024, "%s/info", pathname);
        ret = unlink (filepath);

        if (-1 == ret) {
                gf_log ("", GF_LOG_ERROR, "unlink() failed on path %s,"
                        "errno: %d", filepath, errno);
                goto out;
        }

        ret = rmdir (pathname);

        if (-1 == ret) {
                gf_log ("", GF_LOG_ERROR, "rmdir() failed on path %s,"
                        "errno: %d", pathname, errno);
                goto out;
        }

out:

        gf_log ("", GF_LOG_DEBUG, "Returning %d", ret);

        return ret;
}