From c9ba1ad75d3a63d6f57bb7cc67b3c27d5b6edd03 Mon Sep 17 00:00:00 2001 From: David van Moolenbroek Date: Tue, 29 Nov 2011 16:02:37 +0100 Subject: [PATCH] libpuffs: remove unused block device code --- lib/libpuffs/Makefile | 2 +- lib/libpuffs/device.c | 356 ----------------------------------------- lib/libpuffs/drivers.h | 17 -- lib/libpuffs/glo.h | 4 - lib/libpuffs/misc.c | 11 ++ lib/libpuffs/mount.c | 47 +----- 6 files changed, 14 insertions(+), 423 deletions(-) delete mode 100644 lib/libpuffs/device.c delete mode 100644 lib/libpuffs/drivers.h diff --git a/lib/libpuffs/Makefile b/lib/libpuffs/Makefile index 6d18c7122..967ed1312 100644 --- a/lib/libpuffs/Makefile +++ b/lib/libpuffs/Makefile @@ -4,7 +4,7 @@ LIB= puffs CC= clang SRCS= callcontext.c creds.c null.c pnode.c puffs.c subr.c\ table.c link.c misc.c open.c path.c path_puffs.c protect.c\ - read.c stadir.c time.c utility.c mount.c device.c inode.c + read.c stadir.c time.c utility.c mount.c inode.c INCS= puffs.h puffs_msgif.h INCSDIR= /usr/include MAN= puffs.3 puffs_cc.3 puffs_cred.3 puffs_node.3 \ diff --git a/lib/libpuffs/device.c b/lib/libpuffs/device.c deleted file mode 100644 index 92720ede3..000000000 --- a/lib/libpuffs/device.c +++ /dev/null @@ -1,356 +0,0 @@ -#include "fs.h" -#include -#include -#include -#include -#include -#include "drivers.h" - -#include - -FORWARD _PROTOTYPE( int safe_io_conversion, (endpoint_t driver, - cp_grant_id_t *gid, int *op, cp_grant_id_t *gids, endpoint_t *io_ept, - void **buffer, int *vec_grants, size_t bytes)); -FORWARD _PROTOTYPE( void safe_io_cleanup, (cp_grant_id_t, cp_grant_id_t *, - int)); -FORWARD _PROTOTYPE( int gen_opcl, (endpoint_t driver_e, int op, - dev_t dev, endpoint_t proc_e, int flags) ); -FORWARD _PROTOTYPE( int gen_io, (endpoint_t task_nr, message *mess_ptr) ); - - -/*===========================================================================* - * fs_new_driver * - *===========================================================================*/ -PUBLIC int fs_new_driver(void) -{ - /* New driver endpoint for this device */ - dev_t dev; - dev = (dev_t) fs_m_in.REQ_DEV; - driver_endpoints[major(dev)].driver_e = (endpoint_t) fs_m_in.REQ_DRIVER_E; - return(OK); -} - - -/*===========================================================================* - * safe_io_conversion * - *===========================================================================*/ -PRIVATE int safe_io_conversion(driver, gid, op, gids, io_ept, buffer, - vec_grants, bytes) -endpoint_t driver; -cp_grant_id_t *gid; -int *op; -cp_grant_id_t *gids; -endpoint_t *io_ept; -void **buffer; -int *vec_grants; -size_t bytes; -{ - unsigned int j; - int access; - iovec_t *v; - static iovec_t *new_iovec; - - STATICINIT(new_iovec, NR_IOREQS); - - /* Number of grants allocated in vector I/O. */ - *vec_grants = 0; - - /* Driver can handle it - change request to a safe one. */ - - *gid = GRANT_INVALID; - - switch(*op) { - case MFS_DEV_READ: - case MFS_DEV_WRITE: - /* Change to safe op. */ - *op = *op == MFS_DEV_READ ? DEV_READ_S : DEV_WRITE_S; - *gid = cpf_grant_direct(driver, (vir_bytes) *buffer, bytes, - *op == DEV_READ_S ? CPF_WRITE : CPF_READ); - if(*gid == GRANT_INVALID) { - panic("cpf_grant_magic of buffer failed"); - } - - break; - case MFS_DEV_GATHER: - case MFS_DEV_SCATTER: - /* Change to safe op. */ - *op = *op == MFS_DEV_GATHER ? DEV_GATHER_S : DEV_SCATTER_S; - - /* Grant access to my new i/o vector. */ - *gid = cpf_grant_direct(driver, (vir_bytes) new_iovec, - bytes * sizeof(iovec_t), CPF_READ|CPF_WRITE); - if(*gid == GRANT_INVALID) { - panic("cpf_grant_direct of vector failed"); - } - - v = (iovec_t *) *buffer; - - /* Grant access to i/o buffers. */ - for(j = 0; j < bytes; j++) { - if(j >= NR_IOREQS) - panic("vec too big: %u", bytes); - access = (*op == DEV_GATHER_S) ? CPF_WRITE : CPF_READ; - new_iovec[j].iov_addr = gids[j] = - cpf_grant_direct(driver, (vir_bytes) v[j].iov_addr, - (size_t) v[j].iov_size, access); - - if(!GRANT_VALID(gids[j])) { - panic("ext2: grant to iovec buf failed"); - } - new_iovec[j].iov_size = v[j].iov_size; - (*vec_grants)++; - } - - /* Set user's vector to the new one. */ - *buffer = new_iovec; - break; - default: - panic("Illegal operation %d\n", *op); - break; - } - - /* If we have converted to a safe operation, I/O - * endpoint becomes FS if it wasn't already. - */ - if(GRANT_VALID(*gid)) { - *io_ept = SELF_E; - return 1; - } - - /* Not converted to a safe operation (because there is no - * copying involved in this operation). - */ - return 0; -} - -/*===========================================================================* - * safe_io_cleanup * - *===========================================================================*/ -PRIVATE void safe_io_cleanup(gid, gids, gids_size) -cp_grant_id_t gid; -cp_grant_id_t *gids; -int gids_size; -{ -/* Free resources (specifically, grants) allocated by safe_io_conversion(). */ - int j; - - (void) cpf_revoke(gid); - - for(j = 0; j < gids_size; j++) - (void) cpf_revoke(gids[j]); - - return; -} - -/*===========================================================================* - * block_dev_io * - *===========================================================================*/ -PUBLIC int block_dev_io( - int op, /* MFS_DEV_READ, MFS_DEV_WRITE, etc. */ - dev_t dev, /* major-minor device number */ - endpoint_t proc_e, /* in whose address space is buf? */ - void *buffer, /* virtual address of the buffer */ - u64_t pos, /* byte position */ - size_t bytes /* how many bytes to transfer */ -) -{ -/* Read or write from a device. The parameter 'dev' tells which one. */ - int r, safe; - message m; - cp_grant_id_t gid = GRANT_INVALID; - int vec_grants; - int op_used; - void *buf_used; - static cp_grant_id_t *gids; - endpoint_t driver_e; - - STATICINIT(gids, NR_IOREQS); - - /* Determine driver endpoint for this device */ - driver_e = driver_endpoints[major(dev)].driver_e; - - /* See if driver is roughly valid. */ - if (driver_e == NONE) { - lpuffs_debug("%d block_dev_io: no driver for dev %x\n", SELF_E, dev); - return(EDEADEPT); - } - - /* The io vector copying relies on this I/O being for FS itself. */ - if(proc_e != SELF_E) { - lpuffs_debug("%d doing block_dev_io for non-self %d\n", SELF_E, proc_e); - panic("doing block_dev_io for non-self: %d", proc_e); - } - - /* By default, these are right. */ - m.USER_ENDPT = proc_e; - m.ADDRESS = buffer; - buf_used = buffer; - - /* Convert parameters to 'safe mode'. */ - op_used = op; - safe = safe_io_conversion(driver_e, &gid, &op_used, gids, &m.USER_ENDPT, - &buf_used, &vec_grants, bytes); - - /* Set up rest of the message. */ - if (safe) m.IO_GRANT = (char *) gid; - - m.m_type = op_used; - m.DEVICE = minor(dev); - m.POSITION = ex64lo(pos); - m.COUNT = bytes; - m.HIGHPOS = ex64hi(pos); - - /* Call the task. */ - r = sendrec(driver_e, &m); - if(r == OK && m.REP_STATUS == ERESTART) r = EDEADEPT; - - /* As block I/O never SUSPENDs, safe cleanup must be done whether - * the I/O succeeded or not. */ - if (safe) safe_io_cleanup(gid, gids, vec_grants); - - /* RECOVERY: - * - send back dead driver number - * - VFS unmaps it, waits for new driver - * - VFS sends the new driver endp for the FS proc and the request again - */ - if (r != OK) { - if (r == EDEADSRCDST || r == EDEADEPT) { - lpuffs_debug("%d dead driver %d\n", SELF_E, driver_e); - driver_endpoints[major(dev)].driver_e = NONE; - return(r); - } else if (r == ELOCKED) { - lpuffs_debug("%d ELOCKED talking to %d\n", SELF_E, driver_e); - return(r); - } else - panic("call_task: can't send/receive: %d", r); - } else { - /* Did the process we did the sendrec() for get a result? */ - if (m.REP_ENDPT != proc_e) { - lpuffs_debug("%d strange device reply from %d, type = %d, proc " - "= %d (not %d) (2) ignored\n", SELF_E, m.m_source, - m.m_type, proc_e, m.REP_ENDPT); - r = EIO; - } - } - - /* Task has completed. See if call completed. */ - if (m.REP_STATUS == SUSPEND) { - panic("ext2 block_dev_io: driver returned SUSPEND"); - } - - if(buffer != buf_used && r == OK) { - memcpy(buffer, buf_used, bytes * sizeof(iovec_t)); - } - - return(m.REP_STATUS); -} - -/*===========================================================================* - * dev_open * - *===========================================================================*/ -PUBLIC int dev_open( - endpoint_t driver_e, - dev_t dev, /* device to open */ - endpoint_t proc_e, /* process to open for */ - int flags /* mode bits and flags */ -) -{ - int major, r; - - /* Determine the major device number call the device class specific - * open/close routine. (This is the only routine that must check the - * device number for being in range. All others can trust this check.) - */ - major = major(dev); - if (major >= NR_DEVICES) { - lpuffs_debug("Major device number %d not in range\n", major(dev)); - return(EIO); - } - r = gen_opcl(driver_e, DEV_OPEN, dev, proc_e, flags); - if (r == SUSPEND) panic("suspend on open from"); - return(r); -} - - -/*===========================================================================* - * dev_close * - *===========================================================================*/ -PUBLIC void dev_close( - endpoint_t driver_e, - dev_t dev /* device to close */ -) -{ - (void) gen_opcl(driver_e, DEV_CLOSE, dev, 0, 0); -} - - -/*===========================================================================* - * gen_opcl * - *===========================================================================*/ -PRIVATE int gen_opcl( - endpoint_t driver_e, - int op, /* operation, DEV_OPEN or DEV_CLOSE */ - dev_t dev, /* device to open or close */ - endpoint_t proc_e, /* process to open/close for */ - int flags /* mode bits and flags */ -) -{ -/* Called from the dmap struct in table.c on opens & closes of special files.*/ - message dev_mess; - - dev_mess.m_type = op; - dev_mess.DEVICE = minor(dev); - dev_mess.USER_ENDPT = proc_e; - dev_mess.COUNT = flags; - - /* Call the task. */ - (void) gen_io(driver_e, &dev_mess); - - return(dev_mess.REP_STATUS); -} - - -/*===========================================================================* - * gen_io * - *===========================================================================*/ -PRIVATE int gen_io( - endpoint_t task_nr, /* which task to call */ - message *mess_ptr /* pointer to message for task */ -) -{ -/* All file system I/O ultimately comes down to I/O on major/minor device - * pairs. These lead to calls on the following routines via the dmap table. - */ - - int r, proc_e; - - proc_e = mess_ptr->USER_ENDPT; - - r = sendrec(task_nr, mess_ptr); - if(r == OK && mess_ptr->REP_STATUS == ERESTART) - r = EDEADEPT; - - if (r != OK) { - if (r == EDEADSRCDST || r == EDEADEPT) { - lpuffs_debug("fs: dead driver %d\n", task_nr); - panic("should handle crashed drivers"); - return(r); - } - if (r == ELOCKED) { - lpuffs_debug("fs: ELOCKED talking to %d\n", task_nr); - return(r); - } - panic("call_task: can't send/receive: %d", r); - } - - /* Did the process we did the sendrec() for get a result? */ - if (mess_ptr->REP_ENDPT != proc_e) { - lpuffs_debug("fs: strange device reply from %d, type = %d, proc = %d (not " - "%d) (2) ignored\n", mess_ptr->m_source, mess_ptr->m_type, - proc_e, - mess_ptr->REP_ENDPT); - return(EIO); - } - - return(OK); -} diff --git a/lib/libpuffs/drivers.h b/lib/libpuffs/drivers.h deleted file mode 100644 index cbe8032ac..000000000 --- a/lib/libpuffs/drivers.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef LIBPUFFS_DRIVERS_H -#define LIBPUFFS_DRIVERS_H - -/* Args to dev_bio/dev_io */ -#define MFS_DEV_READ 10001 -#define MFS_DEV_WRITE 10002 -#define MFS_DEV_SCATTER 10003 -#define MFS_DEV_GATHER 10004 - -/* Driver endpoints for major devices. Only the block devices - * are mapped here, it's a subset of the mapping in the VFS */ - -EXTERN struct driver_endpoints { - endpoint_t driver_e; -} driver_endpoints[NR_DEVICES]; - -#endif /* LIBPUFFS_DRIVERS_H */ diff --git a/lib/libpuffs/glo.h b/lib/libpuffs/glo.h index db34d56a6..5b3cd9109 100644 --- a/lib/libpuffs/glo.h +++ b/lib/libpuffs/glo.h @@ -11,7 +11,6 @@ #include #include "puffs_msgif.h" -#include "drivers.h" EXTERN struct puffs_usermount *global_pu; @@ -50,9 +49,6 @@ EXTERN char user_path[PATH_MAX+1]; /* pathname to be processed */ EXTERN dev_t fs_dev; /* The device that is handled by this FS proc */ -EXTERN char fs_dev_label[16]; /* Name of the device driver that is handled - * by this FS proc. - */ EXTERN char fs_name[PATH_MAX+1]; EXTERN int unmountdone; diff --git a/lib/libpuffs/misc.c b/lib/libpuffs/misc.c index d9694386f..04f452ebd 100644 --- a/lib/libpuffs/misc.c +++ b/lib/libpuffs/misc.c @@ -51,3 +51,14 @@ PUBLIC int fs_flush() return(OK); } + + +/*===========================================================================* + * fs_new_driver * + *===========================================================================*/ +PUBLIC int fs_new_driver(void) +{ +/* Do not do anything. */ + + return(OK); +} diff --git a/lib/libpuffs/mount.c b/lib/libpuffs/mount.c index eef46a49c..3173198f3 100644 --- a/lib/libpuffs/mount.c +++ b/lib/libpuffs/mount.c @@ -17,51 +17,12 @@ *===========================================================================*/ PUBLIC int fs_readsuper() { - int r = OK; - cp_grant_id_t label_gid; - size_t label_len; - endpoint_t driver_e; struct vattr *root_va; fs_dev = fs_m_in.REQ_DEV; - label_gid = fs_m_in.REQ_GRANT; - label_len = fs_m_in.REQ_PATH_LEN; is_readonly_fs = (fs_m_in.REQ_FLAGS & REQ_RDONLY) ? 1 : 0; is_root_fs = (fs_m_in.REQ_FLAGS & REQ_ISROOT) ? 1 : 0; - if (label_len > sizeof(fs_dev_label)) - return(EINVAL); - - r = sys_safecopyfrom(fs_m_in.m_source, label_gid, 0, - (vir_bytes)fs_dev_label, label_len, D); - if (r != OK) { - lpuffs_debug("%s:%d fs_readsuper: safecopyfrom failed: %d\n", - __FILE__, __LINE__, r); - return(EINVAL); - } - - fs_m_out.RES_DEV = NO_DEV; - - if (strlen(fs_dev_label)) { - /* Map the driver endpoint for this major */ - r= ds_retrieve_label_endpt(fs_dev_label, &driver_e); - if (r != OK) - { - lpuffs_debug("fs_readsuper: ds_retrieve_label_endpt failed for '%s': %d\n", - fs_dev_label, r); - return EINVAL; - } - - driver_endpoints[(fs_dev >> MAJOR) & BYTE].driver_e = driver_e; - - /* Open the device the file system lives on. */ - if (dev_open(driver_e, fs_dev, driver_e, - is_readonly_fs ? R_BIT : (R_BIT|W_BIT)) != OK) { - return(EINVAL); - } - fs_m_out.RES_DEV = fs_dev; - } - /* Open root pnode */ global_pu->pu_pn_root->pn_count = 1; @@ -72,8 +33,9 @@ PUBLIC int fs_readsuper() fs_m_out.RES_FILE_SIZE_LO = root_va->va_size; fs_m_out.RES_UID = root_va->va_uid; fs_m_out.RES_GID = root_va->va_gid; + fs_m_out.RES_CONREQS = 1; - return(r); + return(OK); } @@ -127,11 +89,6 @@ PUBLIC int fs_unmount() fs_sync(); - if (strlen(fs_dev_label)) { - /* Close the device the file system lives on. */ - dev_close(driver_endpoints[(fs_dev >> MAJOR) & BYTE].driver_e, fs_dev); - } - /* Finish off the unmount. */ PU_SETSTATE(global_pu, PUFFS_STATE_UNMOUNTED); unmountdone = TRUE; -- 2.44.0