summaryrefslogtreecommitdiffstats
path: root/xlators/meta/src/view.c
blob: 704f878bea73bfbb698203bc5bdbf6d04b6dd7c1 (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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/*
  Copyright (c) 2008-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.
*/

#ifndef _CONFIG_H
#define _CONFIG_H
#include "config.h"
#endif

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

#include "meta.h"

/* 
 * This file contains fops for the files and directories in 
 * an xlator directory
 */

/* /.meta/xlators/.../type */

int32_t
meta_xlator_type_readv (call_frame_t *frame, xlator_t *this,
			dict_t *fd, size_t size, off_t offset)
{
  meta_private_t *priv = (meta_private_t *) this->private;
  meta_dirent_t *root = priv->tree;
  data_t *path_data = dict_get (fd, this->name);

  if (path_data) {
    const char *path = data_to_str (path_data);
    meta_dirent_t *file = lookup_meta_entry (root, path, NULL);
    xlator_t *view_xlator = file->view_xlator;

    int type_size;
    type_size = strlen (view_xlator->type);
  
    struct iovec vec;
    vec.iov_base = view_xlator->type + offset;
    vec.iov_len  = min (type_size - offset, size);

    STACK_UNWIND (frame, vec.iov_len, 0, &vec, 1);
    return 0;
  }
}

int32_t
meta_xlator_type_getattr (call_frame_t *frame, 
			  xlator_t *this,
			  const char *path)
{
  meta_private_t *priv = (meta_private_t *) this->private;
  meta_dirent_t *root = priv->tree;

  meta_dirent_t *file = lookup_meta_entry (root, path, NULL);
  xlator_t *view_xlator = file->view_xlator;
  file->stbuf->st_size = strlen (view_xlator->type);

  STACK_UNWIND (frame, 0, 0, file->stbuf);
  return 0;
}

struct xlator_fops meta_xlator_type_fops = {
  .readv   = meta_xlator_type_readv,
  .getattr = meta_xlator_type_getattr
};

/* 
 * fops for the "view" directory
 * {xlator}/view shows the filesystem as it appears
 * to {xlator}
 */

static int32_t
meta_xlator_view_getattr_cbk (call_frame_t *frame, void *cookie,
			      xlator_t *this, int32_t op_ret, int32_t op_errno,
			      struct stat *buf)
{
  STACK_UNWIND (frame, op_ret, op_errno, buf);
  return 0;
}

int32_t
meta_xlator_view_getattr (call_frame_t *frame, 
			  xlator_t *this,
			  const char *path)
{
  meta_private_t *priv = (meta_private_t *) this->private;
  meta_dirent_t *root = priv->tree;
  char *op_path = NULL;

  meta_dirent_t *file = lookup_meta_entry (root, path, &op_path);

  if (op_path) {
    STACK_WIND (frame, meta_xlator_view_getattr_cbk, file->view_xlator,
		file->view_xlator->fops->getattr,
		op_path);
  }
  else {
    STACK_UNWIND (frame, 0, 0, file->stbuf);
  }

  return 0;
}

static int32_t
meta_xlator_view_readdir_cbk (call_frame_t *frame, void *cookie,
			      xlator_t *this, int32_t op_ret, int32_t op_errno,
			      dir_entry_t *entries, int32_t count)
{
  STACK_UNWIND (frame, op_ret, op_errno, entries, count);
  return 0;
}

int32_t
meta_xlator_view_readdir (call_frame_t *frame,
			  xlator_t *this,
			  const char *path)
{
  meta_private_t *priv = (meta_private_t *) this->private;
  meta_dirent_t *root = priv->tree;
  char *op_path = NULL;

  meta_dirent_t *dir = lookup_meta_entry (root, path, &op_path);

  STACK_WIND (frame, meta_xlator_view_readdir_cbk, 
	      dir->view_xlator, dir->view_xlator->fops->readdir,
	      op_path ? op_path : "/");
  return 0;
}

static int32_t
meta_xlator_view_open_cbk (call_frame_t *frame, void *cookie,
			   xlator_t *this, 
			   int32_t op_ret, int32_t op_errno,
			   dict_t *ctx, struct stat *buf)
{
  STACK_UNWIND (frame, op_ret, op_errno, ctx, buf);
  return 0;
}

int32_t
meta_xlator_view_open (call_frame_t *frame, xlator_t *this,
		       const char *path, int32_t flags, mode_t mode)
{
  meta_private_t *priv = (meta_private_t *) this->private;
  meta_dirent_t *root = priv->tree;
  char *op_path = NULL;

  meta_dirent_t *file = lookup_meta_entry (root, path, &op_path);
  STACK_WIND (frame, meta_xlator_view_open_cbk,
	      file->view_xlator, file->view_xlator->fops->open,
	      op_path, flags, mode);
  return 0;
}

int32_t
meta_xlator_view_create (call_frame_t *frame, xlator_t *this,
			 const char *path, int32_t flags, mode_t mode)
{
  meta_private_t *priv = (meta_private_t *) this->private;
  meta_dirent_t *root = priv->tree;
  char *op_path = NULL;

  meta_dirent_t *file = lookup_meta_entry (root, path, &op_path);
  STACK_WIND (frame, meta_xlator_view_open_cbk,
	      file->view_xlator, file->view_xlator->fops->create,
	      op_path, flags, mode);
  return 0;
}

static int32_t
meta_xlator_view_readv_cbk (call_frame_t *frame, void *cookie,
			    xlator_t *this, int32_t op_ret,
			    int32_t op_errno, struct iovec *vector,
			    int32_t count)
{
  STACK_UNWIND (frame, op_ret, op_errno, vector, count);
  return 0;
}

int32_t
meta_xlator_view_readv (call_frame_t *frame, xlator_t *this,
			dict_t *fd, size_t size, off_t offset)
{
  meta_private_t *priv = (meta_private_t *) this->private;
  meta_dirent_t *root = priv->tree;
  data_t *path_data = dict_get (fd, this->name);

  if (path_data) {
    const char *path = data_to_str (path_data);
    meta_dirent_t *file = lookup_meta_entry (root, path, NULL);

    STACK_WIND (frame, meta_xlator_view_readv_cbk,
		file->view_xlator, file->view_xlator->fops->readv,
		fd, size, offset);
    return 0;
  }

  STACK_UNWIND (frame, -1, EBADFD, NULL, 0);
  return 0;
}

static int32_t
meta_xlator_view_writev_cbk (call_frame_t *frame, void *cookie,
			     xlator_t *this, int32_t op_ret,
			     int32_t op_errno)
{
  STACK_UNWIND (frame, op_ret, op_errno);
  return 0;
}

int32_t
meta_xlator_view_writev (call_frame_t *frame, xlator_t *this,
			 dict_t *fd, 
			 struct iovec *vector, int32_t count, off_t offset)
{
  meta_private_t *priv = (meta_private_t *) this->private;
  meta_dirent_t *root = priv->tree;
  data_t *path_data = dict_get (fd, this->name);

  if (path_data) {
    const char *path = data_to_str (path_data);
    meta_dirent_t *file = lookup_meta_entry (root, path, NULL);

    STACK_WIND (frame, meta_xlator_view_writev_cbk,
		file->view_xlator, file->view_xlator->fops->writev,
		fd, vector, count, offset);
    return 0;
  }

  STACK_UNWIND (frame, -1, EBADFD, NULL, 0);
  return 0;
}

struct xlator_fops meta_xlator_view_fops = {
  .getattr = meta_xlator_view_getattr,
  .readdir = meta_xlator_view_readdir,
  .open    = meta_xlator_view_open,
  .create  = meta_xlator_view_create,
  .readv   = meta_xlator_view_readv,
  .writev  = meta_xlator_view_writev
};