~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/fs/intermezzo/upcall.c

Version: ~ [ linux-5.9 ] ~ [ linux-5.8.14 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.70 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.150 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.200 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.238 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.238 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.85 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
  2  * vim:expandtab:shiftwidth=8:tabstop=8:
  3  *
  4  * Copyright (C) 2001, 2002 Cluster File Systems, Inc. <braam@clusterfs.com>
  5  * Copyright (C) 2001 Tacit Networks, Inc. <phil@off.net>
  6  *
  7  *   This file is part of InterMezzo, http://www.inter-mezzo.org.
  8  *
  9  *   InterMezzo is free software; you can redistribute it and/or
 10  *   modify it under the terms of version 2 of the GNU General Public
 11  *   License as published by the Free Software Foundation.
 12  *
 13  *   InterMezzo is distributed in the hope that it will be useful,
 14  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 15  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 16  *   GNU General Public License for more details.
 17  *
 18  *   You should have received a copy of the GNU General Public License
 19  *   along with InterMezzo; if not, write to the Free Software
 20  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 21  *
 22  * Mostly platform independent upcall operations to a cache manager:
 23  *  -- upcalls
 24  *  -- upcall routines
 25  *
 26  */
 27 
 28 #include <asm/system.h>
 29 #include <asm/segment.h>
 30 #include <asm/signal.h>
 31 #include <linux/signal.h>
 32 
 33 #include <linux/types.h>
 34 #include <linux/kernel.h>
 35 #include <linux/mm.h>
 36 #include <linux/vmalloc.h>
 37 #include <linux/slab.h>
 38 #include <linux/sched.h>
 39 #include <linux/fs.h>
 40 #include <linux/stat.h>
 41 #include <linux/errno.h>
 42 #include <linux/string.h>
 43 #include <asm/uaccess.h>
 44 
 45 #include "intermezzo_lib.h"
 46 #include "intermezzo_fs.h"
 47 #include "intermezzo_psdev.h"
 48 
 49 #include "intermezzo_idl.h"
 50 
 51 /*
 52   At present:
 53   -- Asynchronous calls:
 54    - kml:            give a "more" kml indication to userland
 55    - kml_truncate:   initiate KML truncation
 56    - release_permit: kernel is done with permit
 57   -- Synchronous
 58    - open:           fetch file
 59    - permit:         get a permit
 60 
 61   Errors returned by user level code are positive
 62 
 63  */
 64 
 65 static struct izo_upcall_hdr *upc_pack(__u32 opcode, int pathlen, char *path,
 66                                        char *fsetname, int reclen, char *rec,
 67                                        int *size)
 68 {
 69         struct izo_upcall_hdr *hdr;
 70         char *ptr;
 71         ENTRY;
 72 
 73         *size = sizeof(struct izo_upcall_hdr);
 74         if ( fsetname ) {
 75                 *size += round_strlen(fsetname);
 76         }
 77         if ( path ) { 
 78                 *size += round_strlen(path);
 79         }
 80         if ( rec ) { 
 81                 *size += size_round(reclen);
 82         }
 83         PRESTO_ALLOC(hdr, *size);
 84         if (!hdr) { 
 85                 CERROR("intermezzo upcall: out of memory (opc %d)\n", opcode);
 86                 EXIT;
 87                 return NULL;
 88         }
 89         memset(hdr, 0, *size);
 90 
 91         ptr = (char *)hdr + sizeof(*hdr);
 92 
 93         /* XXX do we need fsuid ? */
 94         hdr->u_len = *size;
 95         hdr->u_version = IZO_UPC_VERSION;
 96         hdr->u_opc = opcode;
 97         hdr->u_pid = current->pid;
 98         hdr->u_uid = current->fsuid;
 99 
100         if (path) { 
101                 /*XXX Robert: please review what len to pass in for 
102                   NUL terminated strings */
103                 hdr->u_pathlen = strlen(path);
104                 LOGL0(path, hdr->u_pathlen, ptr);
105         }
106         if (fsetname) { 
107                 hdr->u_fsetlen = strlen(fsetname);
108                 LOGL0(fsetname, strlen(fsetname), ptr);
109         }
110         if (rec) { 
111                 hdr->u_reclen = reclen;
112                 LOGL(rec, reclen, ptr);
113         }
114         
115         EXIT;
116         return hdr;
117 }
118 
119 /* the upcalls */
120 int izo_upc_kml(int minor, __u64 offset, __u32 first_recno, __u64 length, __u32 last_recno, char *fsetname)
121 {
122         int size;
123         int error;
124         struct izo_upcall_hdr *hdr;
125 
126         ENTRY;
127         if (!presto_lento_up(minor)) {
128                 EXIT;
129                 return 0;
130         }
131 
132         hdr = upc_pack(IZO_UPC_KML, 0, NULL, fsetname, 0, NULL, &size);
133         if (!hdr || IS_ERR(hdr)) {
134                 EXIT;
135                 return -PTR_ERR(hdr);
136         }
137 
138         hdr->u_offset = offset;
139         hdr->u_first_recno = first_recno;
140         hdr->u_length = length;
141         hdr->u_last_recno = last_recno;
142 
143         CDEBUG(D_UPCALL, "KML: fileset %s, offset %Lu, length %Lu, "
144                "first %u, last %d; minor %d\n",
145                fsetname, hdr->u_offset, hdr->u_length, hdr->u_first_recno,
146                hdr->u_last_recno, minor);
147 
148         error = izo_upc_upcall(minor, &size, hdr, ASYNCHRONOUS);
149 
150         EXIT;
151         return -error;
152 }
153 
154 int izo_upc_kml_truncate(int minor, __u64 length, __u32 last_recno, char *fsetname)
155 {
156         int size;
157         int error;
158         struct izo_upcall_hdr *hdr;
159 
160         ENTRY;
161         if (!presto_lento_up(minor)) {
162                 EXIT;
163                 return 0;
164         }
165 
166         hdr = upc_pack(IZO_UPC_KML_TRUNC, 0, NULL, fsetname, 0, NULL, &size);
167         if (!hdr || IS_ERR(hdr)) {
168                 EXIT;
169                 return -PTR_ERR(hdr);
170         }
171 
172         hdr->u_length = length;
173         hdr->u_last_recno = last_recno;
174 
175         CDEBUG(D_UPCALL, "KML TRUNCATE: fileset %s, length %Lu, "
176                "last recno %d, minor %d\n",
177                fsetname, hdr->u_length, hdr->u_last_recno, minor);
178 
179         error = izo_upc_upcall(minor, &size, hdr, ASYNCHRONOUS);
180 
181         EXIT;
182         return error;
183 }
184 
185 int izo_upc_open(int minor, __u32 pathlen, char *path, char *fsetname, struct lento_vfs_context *info)
186 {
187         int size;
188         int error;
189         struct izo_upcall_hdr *hdr;
190         ENTRY;
191 
192         if (!presto_lento_up(minor)) {
193                 EXIT;
194                 return -EIO;
195         }
196 
197         hdr = upc_pack(IZO_UPC_OPEN, pathlen, path, fsetname, 
198                        sizeof(*info), (char*)info, &size);
199         if (!hdr || IS_ERR(hdr)) {
200                 EXIT;
201                 return -PTR_ERR(hdr);
202         }
203 
204         CDEBUG(D_UPCALL, "path %s\n", path);
205 
206         error = izo_upc_upcall(minor, &size, hdr, SYNCHRONOUS);
207         if (error)
208                 CERROR("InterMezzo: %s: error %d\n", __FUNCTION__, error);
209 
210         EXIT;
211         return -error;
212 }
213 
214 int izo_upc_get_fileid(int minor, __u32 reclen, char *rec, 
215                        __u32 pathlen, char *path, char *fsetname)
216 {
217         int size;
218         int error;
219         struct izo_upcall_hdr *hdr;
220         ENTRY;
221 
222         if (!presto_lento_up(minor)) {
223                 EXIT;
224                 return -EIO;
225         }
226 
227         hdr = upc_pack(IZO_UPC_GET_FILEID, pathlen, path, fsetname, reclen, rec, &size);
228         if (!hdr || IS_ERR(hdr)) {
229                 EXIT;
230                 return -PTR_ERR(hdr);
231         }
232 
233         CDEBUG(D_UPCALL, "path %s\n", path);
234 
235         error = izo_upc_upcall(minor, &size, hdr, SYNCHRONOUS);
236         if (error)
237                 CERROR("InterMezzo: %s: error %d\n", __FUNCTION__, error);
238 
239         EXIT;
240         return -error;
241 }
242 
243 int izo_upc_backfetch(int minor, char *path, char *fsetname, struct lento_vfs_context *info)
244 {
245         int size;
246         int error;
247         struct izo_upcall_hdr *hdr;
248         ENTRY;
249 
250         if (!presto_lento_up(minor)) {
251                 EXIT;
252                 return -EIO;
253         }
254 
255         hdr = upc_pack(IZO_UPC_BACKFETCH, strlen(path), path, fsetname, 
256                        sizeof(*info), (char *)info, &size);
257         if (!hdr || IS_ERR(hdr)) {
258                 EXIT;
259                 return -PTR_ERR(hdr);
260         }
261 
262         /* This is currently synchronous, kml_reint_record blocks */
263         error = izo_upc_upcall(minor, &size, hdr, SYNCHRONOUS);
264         if (error)
265                 CERROR("InterMezzo: %s: error %d\n", __FUNCTION__, error);
266 
267         EXIT;
268         return -error;
269 }
270 
271 int izo_upc_permit(int minor, struct dentry *dentry, __u32 pathlen, char *path,
272                    char *fsetname)
273 {
274         int size;
275         int error;
276         struct izo_upcall_hdr *hdr;
277 
278         ENTRY;
279 
280         hdr = upc_pack(IZO_UPC_PERMIT, pathlen, path, fsetname, 0, NULL, &size);
281         if (!hdr || IS_ERR(hdr)) {
282                 EXIT;
283                 return -PTR_ERR(hdr);
284         }
285 
286         CDEBUG(D_UPCALL, "Permit minor %d path %s\n", minor, path);
287 
288         error = izo_upc_upcall(minor, &size, hdr, SYNCHRONOUS);
289 
290         if (error == -EROFS) {
291                 int err;
292                 CERROR("InterMezzo: ERROR - requested permit for read-only "
293                        "fileset.\n   Setting \"%s\" read-only!\n", path);
294                 err = izo_mark_cache(dentry, 0xFFFFFFFF, CACHE_CLIENT_RO, NULL);
295                 if (err)
296                         CERROR("InterMezzo ERROR: mark_cache %d\n", err);
297         } else if (error) {
298                 CERROR("InterMezzo: %s: error %d\n", __FUNCTION__, error);
299         }
300 
301         EXIT;
302         return error;
303 }
304 
305 /* This is a ping-pong upcall handled on the server when a client (uuid)
306  * requests the permit for itself. */
307 int izo_upc_revoke_permit(int minor, char *fsetname, __u8 uuid[16])
308 {
309         int size;
310         int error;
311         struct izo_upcall_hdr *hdr;
312 
313         ENTRY;
314 
315         hdr = upc_pack(IZO_UPC_REVOKE_PERMIT, 0, NULL, fsetname, 0, NULL, &size);
316         if (!hdr || IS_ERR(hdr)) {
317                 EXIT;
318                 return -PTR_ERR(hdr);
319         }
320 
321         memcpy(hdr->u_uuid, uuid, sizeof(hdr->u_uuid));
322 
323         error = izo_upc_upcall(minor, &size, hdr, SYNCHRONOUS);
324 
325         if (error)
326                 CERROR("InterMezzo: %s: error %d\n", __FUNCTION__, error);
327 
328         EXIT;
329         return -error;
330 }
331 
332 int izo_upc_go_fetch_kml(int minor, char *fsetname, __u8 uuid[16],
333                          __u64 kmlsize)
334 {
335         int size;
336         int error;
337         struct izo_upcall_hdr *hdr;
338         ENTRY;
339 
340         if (!presto_lento_up(minor)) {
341                 EXIT;
342                 return -EIO;
343         }
344 
345         hdr = upc_pack(IZO_UPC_GO_FETCH_KML, 0, NULL, fsetname, 0, NULL, &size);
346         if (!hdr || IS_ERR(hdr)) {
347                 EXIT;
348                 return -PTR_ERR(hdr);
349         }
350 
351         hdr->u_offset = kmlsize;
352         memcpy(hdr->u_uuid, uuid, sizeof(hdr->u_uuid));
353 
354         error = izo_upc_upcall(minor, &size, hdr, ASYNCHRONOUS);
355         if (error)
356                 CERROR("%s: error %d\n", __FUNCTION__, error);
357 
358         EXIT;
359         return -error;
360 }
361 
362 int izo_upc_connect(int minor, __u64 ip_address, __u64 port, __u8 uuid[16],
363                     int client_flag)
364 {
365         int size;
366         int error;
367         struct izo_upcall_hdr *hdr;
368         ENTRY;
369 
370         if (!presto_lento_up(minor)) {
371                 EXIT;
372                 return -EIO;
373         }
374 
375         hdr = upc_pack(IZO_UPC_CONNECT, 0, NULL, NULL, 0, NULL, &size);
376         if (!hdr || IS_ERR(hdr)) {
377                 EXIT;
378                 return -PTR_ERR(hdr);
379         }
380 
381         hdr->u_offset = ip_address;
382         hdr->u_length = port;
383         memcpy(hdr->u_uuid, uuid, sizeof(hdr->u_uuid));
384         hdr->u_first_recno = client_flag;
385 
386         error = izo_upc_upcall(minor, &size, hdr, SYNCHRONOUS);
387         if (error) {
388                 CERROR("%s: error %d\n", __FUNCTION__, error);
389         }
390 
391         EXIT;
392         return -error;
393 }
394 
395 int izo_upc_set_kmlsize(int minor, char *fsetname, __u8 uuid[16], __u64 kmlsize)
396 {
397         int size;
398         int error;
399         struct izo_upcall_hdr *hdr;
400         ENTRY;
401 
402         if (!presto_lento_up(minor)) {
403                 EXIT;
404                 return -EIO;
405         }
406 
407         hdr = upc_pack(IZO_UPC_SET_KMLSIZE, 0, NULL, fsetname, 0, NULL, &size);
408         if (!hdr || IS_ERR(hdr)) {
409                 EXIT;
410                 return -PTR_ERR(hdr);
411         }
412 
413         memcpy(hdr->u_uuid, uuid, sizeof(hdr->u_uuid));
414         hdr->u_length = kmlsize;
415 
416         error = izo_upc_upcall(minor, &size, hdr, SYNCHRONOUS);
417         if (error)
418                 CERROR("%s: error %d\n", __FUNCTION__, error);
419 
420         EXIT;
421         return -error;
422 }
423 
424 int izo_upc_repstatus(int minor,  char * fsetname, struct izo_rcvd_rec *lr_server)
425 {
426         int size;
427         int error;
428         struct izo_upcall_hdr *hdr;
429         ENTRY;
430 
431         if (!presto_lento_up(minor)) {
432                 EXIT;
433                 return -EIO;
434         }
435 
436         hdr = upc_pack(IZO_UPC_REPSTATUS, 0, NULL, fsetname, 
437                        sizeof(*lr_server), (char*)lr_server, 
438                        &size);
439         if (!hdr || IS_ERR(hdr)) {
440                 EXIT;
441                 return -PTR_ERR(hdr);
442         }
443 
444         error = izo_upc_upcall(minor, &size, hdr, SYNCHRONOUS);
445         if (error)
446                 CERROR("%s: error %d\n", __FUNCTION__, error);
447 
448         EXIT;
449         return -error;
450 }
451 
452 
453 #if 0
454 int izo_upc_client_make_branch(int minor, char *fsetname, char *tagname,
455                                char *branchname)
456 {
457         int size, error;
458         struct izo_upcall_hdr *hdr;
459         int pathlen;
460         char *path;
461         ENTRY;
462 
463         hdr = upc_pack(IZO_UPC_CLIENT_MAKE_BRANCH, strlen(tagname), tagname,
464                        fsetname, strlen(branchname) + 1, branchname, &size);
465         if (!hdr || IS_ERR(hdr)) {
466                 error = -PTR_ERR(hdr);
467                 goto error;
468         }
469 
470         error = izo_upc_upcall(minor, &size, hdr, SYNCHRONOUS);
471         if (error)
472                 CERROR("InterMezzo: error %d\n", error);
473 
474  error:
475         PRESTO_FREE(path, pathlen);
476         EXIT;
477         return error;
478 }
479 #endif
480 
481 int izo_upc_server_make_branch(int minor, char *fsetname)
482 {
483         int size, error;
484         struct izo_upcall_hdr *hdr;
485         ENTRY;
486 
487         hdr = upc_pack(IZO_UPC_SERVER_MAKE_BRANCH, 0, NULL, fsetname, 0, NULL, &size);
488         if (!hdr || IS_ERR(hdr)) {
489                 error = -PTR_ERR(hdr);
490                 goto error;
491         }
492 
493         error = izo_upc_upcall(minor, &size, hdr, SYNCHRONOUS);
494         if (error)
495                 CERROR("InterMezzo: error %d\n", error);
496 
497  error:
498         EXIT;
499         return -error;
500 }
501 
502 int izo_upc_branch_undo(int minor, char *fsetname, char *branchname)
503 {
504         int size;
505         int error;
506         struct izo_upcall_hdr *hdr;
507         ENTRY;
508 
509         if (!presto_lento_up(minor)) {
510                 EXIT;
511                 return -EIO;
512         }
513 
514         hdr = upc_pack(IZO_UPC_BRANCH_UNDO, strlen(branchname), branchname,
515                        fsetname, 0, NULL, &size);
516         if (!hdr || IS_ERR(hdr)) {
517                 EXIT;
518                 return -PTR_ERR(hdr);
519         }
520 
521         error = izo_upc_upcall(minor, &size, hdr, SYNCHRONOUS);
522         if (error)
523                 CERROR("InterMezzo: %s: error %d\n", __FUNCTION__, error);
524 
525         EXIT;
526         return -error;
527 }
528 
529 int izo_upc_branch_redo(int minor, char *fsetname, char *branchname)
530 {
531         int size;
532         int error;
533         struct izo_upcall_hdr *hdr;
534         ENTRY;
535 
536         if (!presto_lento_up(minor)) {
537                 EXIT;
538                 return -EIO;
539         }
540 
541         hdr = upc_pack(IZO_UPC_BRANCH_REDO, strlen(branchname) + 1, branchname,
542                        fsetname, 0, NULL, &size);
543         if (!hdr || IS_ERR(hdr)) {
544                 EXIT;
545                 return -PTR_ERR(hdr);
546         }
547 
548         error = izo_upc_upcall(minor, &size, hdr, SYNCHRONOUS);
549         if (error)
550                 CERROR("InterMezzo: %s: error %d\n", __FUNCTION__, error);
551 
552         EXIT;
553         return -error;
554 }
555 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp