1 /*
2 Copyright 2017 Skytechnology sp. z o.o.
3
4 This file is part of LizardFS.
5
6 LizardFS is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, version 3.
9
10 LizardFS is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with LizardFS. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include "context_wrap.h"
20 #include "lzfs_internal.h"
21
liz_cred_lookup(liz_t * instance,struct user_cred * cred,liz_inode_t parent,const char * path,struct liz_entry * entry)22 int liz_cred_lookup(liz_t *instance, struct user_cred *cred, liz_inode_t parent, const char *path,
23 struct liz_entry *entry) {
24 liz_context_t *ctx = lzfs_fsal_create_context(instance, cred);
25 if (ctx == NULL) {
26 return -1;
27 }
28 int rc = liz_lookup(instance, ctx, parent, path, entry);
29 liz_destroy_context(ctx);
30 return rc;
31 }
32
liz_cred_mknod(liz_t * instance,struct user_cred * cred,liz_inode_t parent,const char * path,mode_t mode,dev_t rdev,struct liz_entry * entry)33 int liz_cred_mknod(liz_t *instance, struct user_cred *cred, liz_inode_t parent, const char *path,
34 mode_t mode, dev_t rdev, struct liz_entry *entry) {
35 liz_context_t *ctx = lzfs_fsal_create_context(instance, cred);
36 if (ctx == NULL) {
37 return -1;
38 }
39 int rc = liz_mknod(instance, ctx, parent, path, mode, rdev, entry);
40 liz_destroy_context(ctx);
41 return rc;
42 }
43
liz_cred_open(liz_t * instance,struct user_cred * cred,liz_inode_t inode,int flags)44 liz_fileinfo_t *liz_cred_open(liz_t *instance, struct user_cred *cred, liz_inode_t inode,
45 int flags) {
46 liz_context_t *ctx = lzfs_fsal_create_context(instance, cred);
47 if (ctx == NULL) {
48 return NULL;
49 }
50 liz_fileinfo_t *ret = liz_open(instance, ctx, inode, flags);
51 liz_destroy_context(ctx);
52 return ret;
53 }
54
liz_cred_read(liz_t * instance,struct user_cred * cred,liz_fileinfo_t * fileinfo,off_t offset,size_t size,char * buffer)55 ssize_t liz_cred_read(liz_t *instance, struct user_cred *cred, liz_fileinfo_t *fileinfo,
56 off_t offset, size_t size, char *buffer) {
57 liz_context_t *ctx = lzfs_fsal_create_context(instance, cred);
58 if (ctx == NULL) {
59 return -1;
60 }
61 ssize_t ret = liz_read(instance, ctx, fileinfo, offset, size, buffer);
62 liz_destroy_context(ctx);
63 return ret;
64 }
65
liz_cred_write(liz_t * instance,struct user_cred * cred,liz_fileinfo_t * fileinfo,off_t offset,size_t size,const char * buffer)66 ssize_t liz_cred_write(liz_t *instance, struct user_cred *cred, liz_fileinfo_t *fileinfo,
67 off_t offset, size_t size, const char *buffer) {
68 liz_context_t *ctx = lzfs_fsal_create_context(instance, cred);
69 if (ctx == NULL) {
70 return -1;
71 }
72 ssize_t ret = liz_write(instance, ctx, fileinfo, offset, size, buffer);
73 liz_destroy_context(ctx);
74 return ret;
75 }
76
liz_cred_flush(liz_t * instance,struct user_cred * cred,liz_fileinfo_t * fileinfo)77 int liz_cred_flush(liz_t *instance, struct user_cred *cred, liz_fileinfo_t *fileinfo) {
78 liz_context_t *ctx = lzfs_fsal_create_context(instance, cred);
79 if (ctx == NULL) {
80 return -1;
81 }
82 int rc = liz_flush(instance, ctx, fileinfo);
83 liz_destroy_context(ctx);
84 return rc;
85 }
86
liz_cred_getattr(liz_t * instance,struct user_cred * cred,liz_inode_t inode,struct liz_attr_reply * reply)87 int liz_cred_getattr(liz_t *instance, struct user_cred *cred, liz_inode_t inode,
88 struct liz_attr_reply *reply) {
89 liz_context_t *ctx = lzfs_fsal_create_context(instance, cred);
90 if (ctx == NULL) {
91 return -1;
92 }
93 int rc = liz_getattr(instance, ctx, inode, reply);
94 liz_destroy_context(ctx);
95 return rc;
96 }
97
liz_cred_opendir(liz_t * instance,struct user_cred * cred,liz_inode_t inode)98 liz_fileinfo_t *liz_cred_opendir(liz_t *instance, struct user_cred *cred, liz_inode_t inode) {
99 liz_context_t *ctx = lzfs_fsal_create_context(instance, cred);
100 if (ctx == NULL) {
101 return NULL;
102 }
103 liz_fileinfo_t *ret = liz_opendir(instance, ctx, inode);
104 liz_destroy_context(ctx);
105 return ret;
106 }
107
liz_cred_readdir(liz_t * instance,struct user_cred * cred,struct liz_fileinfo * fileinfo,off_t offset,size_t max_entries,struct liz_direntry * buf,size_t * num_entries)108 int liz_cred_readdir(liz_t *instance, struct user_cred *cred, struct liz_fileinfo *fileinfo,
109 off_t offset, size_t max_entries, struct liz_direntry *buf,
110 size_t *num_entries) {
111 liz_context_t *ctx = lzfs_fsal_create_context(instance, cred);
112 if (ctx == NULL) {
113 return -1;
114 }
115 int rc = liz_readdir(instance, ctx, fileinfo, offset, max_entries, buf, num_entries);
116 liz_destroy_context(ctx);
117 return rc;
118 }
119
liz_cred_mkdir(liz_t * instance,struct user_cred * cred,liz_inode_t parent,const char * name,mode_t mode,struct liz_entry * out_entry)120 int liz_cred_mkdir(liz_t *instance, struct user_cred *cred, liz_inode_t parent, const char *name,
121 mode_t mode, struct liz_entry *out_entry) {
122 liz_context_t *ctx = lzfs_fsal_create_context(instance, cred);
123 if (ctx == NULL) {
124 return -1;
125 }
126 int rc = liz_mkdir(instance, ctx, parent, name, mode, out_entry);
127 liz_destroy_context(ctx);
128 return rc;
129 }
130
liz_cred_rmdir(liz_t * instance,struct user_cred * cred,liz_inode_t parent,const char * name)131 int liz_cred_rmdir(liz_t *instance, struct user_cred *cred, liz_inode_t parent, const char *name) {
132 liz_context_t *ctx = lzfs_fsal_create_context(instance, cred);
133 if (ctx == NULL) {
134 return -1;
135 }
136 int rc = liz_rmdir(instance, ctx, parent, name);
137 liz_destroy_context(ctx);
138 return rc;
139 }
140
liz_cred_unlink(liz_t * instance,struct user_cred * cred,liz_inode_t parent,const char * name)141 int liz_cred_unlink(liz_t *instance, struct user_cred *cred, liz_inode_t parent, const char *name) {
142 liz_context_t *ctx = lzfs_fsal_create_context(instance, cred);
143 if (ctx == NULL) {
144 return -1;
145 }
146 int rc = liz_unlink(instance, ctx, parent, name);
147 liz_destroy_context(ctx);
148 return rc;
149 }
150
liz_cred_setattr(liz_t * instance,struct user_cred * cred,liz_inode_t inode,struct stat * stbuf,int to_set,struct liz_attr_reply * reply)151 int liz_cred_setattr(liz_t *instance, struct user_cred *cred, liz_inode_t inode, struct stat *stbuf,
152 int to_set, struct liz_attr_reply *reply) {
153 liz_context_t *ctx = lzfs_fsal_create_context(instance, cred);
154 if (ctx == NULL) {
155 return -1;
156 }
157 int rc = liz_setattr(instance, ctx, inode, stbuf, to_set, reply);
158 liz_destroy_context(ctx);
159 return rc;
160 }
161
liz_cred_fsync(liz_t * instance,struct user_cred * cred,struct liz_fileinfo * fileinfo)162 int liz_cred_fsync(liz_t *instance, struct user_cred *cred, struct liz_fileinfo *fileinfo) {
163 liz_context_t *ctx = lzfs_fsal_create_context(instance, cred);
164 if (ctx == NULL) {
165 return -1;
166 }
167 int rc = liz_fsync(instance, ctx, fileinfo);
168 liz_destroy_context(ctx);
169 return rc;
170 }
171
liz_cred_rename(liz_t * instance,struct user_cred * cred,liz_inode_t parent,const char * name,liz_inode_t new_parent,const char * new_name)172 int liz_cred_rename(liz_t *instance, struct user_cred *cred, liz_inode_t parent, const char *name,
173 liz_inode_t new_parent, const char *new_name) {
174 liz_context_t *ctx = lzfs_fsal_create_context(instance, cred);
175 if (ctx == NULL) {
176 return -1;
177 }
178 int rc = liz_rename(instance, ctx, parent, name, new_parent, new_name);
179 liz_destroy_context(ctx);
180 return rc;
181 }
182
liz_cred_symlink(liz_t * instance,struct user_cred * cred,const char * link,liz_inode_t parent,const char * name,struct liz_entry * entry)183 int liz_cred_symlink(liz_t *instance, struct user_cred *cred, const char *link, liz_inode_t parent,
184 const char *name, struct liz_entry *entry) {
185 liz_context_t *ctx = lzfs_fsal_create_context(instance, cred);
186 if (ctx == NULL) {
187 return -1;
188 }
189 int rc = liz_symlink(instance, ctx, link, parent, name, entry);
190 liz_destroy_context(ctx);
191 return rc;
192 }
193
liz_cred_readlink(liz_t * instance,struct user_cred * cred,liz_inode_t inode,char * buf,size_t size)194 int liz_cred_readlink(liz_t *instance, struct user_cred *cred, liz_inode_t inode, char *buf,
195 size_t size) {
196 liz_context_t *ctx = lzfs_fsal_create_context(instance, cred);
197 if (ctx == NULL) {
198 return -1;
199 }
200 int rc = liz_readlink(instance, ctx, inode, buf, size);
201 liz_destroy_context(ctx);
202 return rc;
203 }
204
liz_cred_link(liz_t * instance,struct user_cred * cred,liz_inode_t inode,liz_inode_t parent,const char * name,struct liz_entry * entry)205 int liz_cred_link(liz_t *instance, struct user_cred *cred, liz_inode_t inode, liz_inode_t parent,
206 const char *name, struct liz_entry *entry) {
207 liz_context_t *ctx = lzfs_fsal_create_context(instance, cred);
208 if (ctx == NULL) {
209 return -1;
210 }
211 int rc = liz_link(instance, ctx, inode, parent, name, entry);
212 liz_destroy_context(ctx);
213 return rc;
214 }
215
liz_cred_get_chunks_info(liz_t * instance,struct user_cred * cred,liz_inode_t inode,uint32_t chunk_index,liz_chunk_info_t * buffer,uint32_t buffer_size,uint32_t * reply_size)216 int liz_cred_get_chunks_info(liz_t *instance, struct user_cred *cred, liz_inode_t inode,
217 uint32_t chunk_index, liz_chunk_info_t *buffer, uint32_t buffer_size,
218 uint32_t *reply_size) {
219 liz_context_t *ctx = lzfs_fsal_create_context(instance, cred);
220 if (ctx == NULL) {
221 return -1;
222 }
223 int rc =
224 liz_get_chunks_info(instance, ctx, inode, chunk_index, buffer, buffer_size, reply_size);
225 liz_destroy_context(ctx);
226 return rc;
227 }
228
liz_cred_setacl(liz_t * instance,struct user_cred * cred,liz_inode_t inode,const liz_acl_t * acl)229 int liz_cred_setacl(liz_t *instance, struct user_cred *cred, liz_inode_t inode,
230 const liz_acl_t *acl) {
231 liz_context_t *ctx = lzfs_fsal_create_context(instance, cred);
232 if (ctx == NULL) {
233 return -1;
234 }
235 int rc = liz_setacl(instance, ctx, inode, acl);
236 liz_destroy_context(ctx);
237 return rc;
238 }
239
liz_cred_getacl(liz_t * instance,struct user_cred * cred,liz_inode_t inode,liz_acl_t ** acl)240 int liz_cred_getacl(liz_t *instance, struct user_cred *cred, liz_inode_t inode, liz_acl_t **acl) {
241 liz_context_t *ctx = lzfs_fsal_create_context(instance, cred);
242 if (ctx == NULL) {
243 return -1;
244 }
245 int rc = liz_getacl(instance, ctx, inode, acl);
246 liz_destroy_context(ctx);
247 return rc;
248 }
249
liz_cred_setlk(liz_t * instance,struct user_cred * cred,liz_fileinfo_t * fileinfo,const liz_lock_info_t * lock)250 int liz_cred_setlk(liz_t *instance, struct user_cred *cred, liz_fileinfo_t *fileinfo,
251 const liz_lock_info_t *lock) {
252 liz_context_t *ctx = lzfs_fsal_create_context(instance, cred);
253 if (ctx == NULL) {
254 return -1;
255 }
256 int rc = liz_setlk(instance, ctx, fileinfo, lock, NULL, NULL);
257 liz_destroy_context(ctx);
258 return rc;
259 }
260
liz_cred_getlk(liz_t * instance,struct user_cred * cred,liz_fileinfo_t * fileinfo,liz_lock_info_t * lock)261 int liz_cred_getlk(liz_t *instance, struct user_cred *cred, liz_fileinfo_t *fileinfo,
262 liz_lock_info_t *lock) {
263 liz_context_t *ctx = lzfs_fsal_create_context(instance, cred);
264 if (ctx == NULL) {
265 return -1;
266 }
267 int rc = liz_getlk(instance, ctx, fileinfo, lock);
268 return rc;
269 }
270