summaryrefslogtreecommitdiffstats
path: root/api/src/glfs-master.c
blob: ff8f68f452b64c28aba8e5b403c0002f9e7a7560 (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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*
  Copyright (c) 2012 Red Hat, Inc. <http://www.redhat.com>
  This file is part of GlusterFS.

  This file is licensed to you under your choice of the GNU Lesser
  General Public License, version 3 or any later version (LGPLv3 or
  later), or the GNU General Public License, version 2 (GPLv2), in all
  cases as published by the Free Software Foundation.
*/

#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <inttypes.h>
#include <limits.h>

#include "xlator.h"
#include "glusterfs.h"

#include "glfs-internal.h"
#include "glfs-mem-types.h"
#include "gfapi-messages.h"


int
graph_setup (struct glfs *fs, glusterfs_graph_t *graph)
{
	xlator_t      *new_subvol = NULL;
	xlator_t      *old_subvol = NULL;
	inode_table_t *itable = NULL;
	int            ret = -1;

	new_subvol = graph->top;

	/* This is called in a bottom-up context, it should specifically
	   NOT be glfs_lock()
	*/
	pthread_mutex_lock (&fs->mutex);
	{
		if (new_subvol->switched ||
		    new_subvol == fs->active_subvol ||
		    new_subvol == fs->next_subvol) {
			/* Spurious CHILD_UP event on old graph */
			ret = 0;
			goto unlock;
		}

		if (!new_subvol->itable) {
			itable = inode_table_new (131072, new_subvol);
			if (!itable) {
				errno = ENOMEM;
				ret = -1;
				goto unlock;
			}

			new_subvol->itable = itable;
		}

		old_subvol = fs->next_subvol;
		fs->next_subvol = new_subvol;
		fs->next_subvol->winds++; /* first ref */
		ret = 0;
	}
unlock:
	pthread_mutex_unlock (&fs->mutex);

	if (old_subvol)
		/* wasn't picked up so far, skip */
		glfs_subvol_done (fs, old_subvol);

	return ret;
}


int
notify (xlator_t *this, int event, void *data, ...)
{
	glusterfs_graph_t   *graph = NULL;
	struct glfs	    *fs = NULL;

	graph = data;
	fs = this->private;

	switch (event) {
	case GF_EVENT_GRAPH_NEW:
		gf_msg (this->name, GF_LOG_INFO, 0, API_MSG_NEW_GRAPH,
                        "New graph %s (%d) coming up",
			uuid_utoa ((unsigned char *)graph->graph_uuid),
			graph->id);
		break;
	case GF_EVENT_CHILD_UP:
                pthread_mutex_lock (&fs->mutex);
                {
                        graph->used = 1;
                }
                pthread_mutex_unlock (&fs->mutex);
		graph_setup (fs, graph);
		glfs_init_done (fs, 0);
		break;
	case GF_EVENT_CHILD_DOWN:
                pthread_mutex_lock (&fs->mutex);
                {
                        graph->used = 0;
                        pthread_cond_broadcast (&fs->child_down_cond);
                }
                pthread_mutex_unlock (&fs->mutex);
		graph_setup (fs, graph);
		glfs_init_done (fs, 1);
		break;
	case GF_EVENT_CHILD_CONNECTING:
		break;
        case GF_EVENT_UPCALL:
                glfs_process_upcall_event (fs, data);
                break;
	default:
		gf_msg_debug (this->name, 0, "got notify event %d", event);
		break;
	}

	return 0;
}


int
mem_acct_init (xlator_t *this)
{
	int ret = -1;

	if (!this)
		return ret;

	ret = xlator_mem_acct_init (this, glfs_mt_end + 1);
	if (ret) {
		gf_msg (this->name, GF_LOG_ERROR, ENOMEM,
                        API_MSG_MEM_ACCT_INIT_FAILED, "Failed to initialise "
                        "memory accounting");
		return ret;
	}

	return 0;
}


int
init (xlator_t *this)
{
	return 0;
}


void
fini (xlator_t *this)
{

}

/* place-holder fops */
int
glfs_forget (xlator_t *this, inode_t *inode)
{
	return 0;
}

int
glfs_release (xlator_t *this, fd_t *fd)
{
	return 0;
}

int
glfs_releasedir (xlator_t *this, fd_t *fd)
{
	return 0;
}

struct xlator_dumpops dumpops;


struct xlator_fops fops;


struct xlator_cbks cbks = {
	.forget	    = glfs_forget,
	.release    = glfs_release,
	.releasedir = glfs_releasedir
};