/* this file implements the /dev/pvfs2-req device node */
uint32_t orangefs_userspace_version;
staticint open_access_count;
static DEFINE_MUTEX(devreq_mutex);
#define DUMP_DEVICE_ERROR() \ do { \
gossip_err("*****************************************************\n");\
gossip_err("ORANGEFS Device Error: You cannot open the device file "); \
gossip_err("\n/dev/%s more than once. Please make sure that\nthere " \ "are no ", ORANGEFS_REQDEVICE_NAME); \
gossip_err("instances of a program using this device\ncurrently " \ "running. (You must verify this!)\n"); \
gossip_err("For example, you can use the lsof program as follows:\n");\
gossip_err("'lsof | grep %s' (run this as root)\n", \
ORANGEFS_REQDEVICE_NAME); \
gossip_err(" open_access_count = %d\n", open_access_count); \
gossip_err("*****************************************************\n");\
} while (0)
staticint hash_func(__u64 tag, int table_size)
{ return do_div(tag, (unsignedint)table_size);
}
staticvoid orangefs_devreq_add_op(struct orangefs_kernel_op_s *op)
{ int index = hash_func(op->tag, hash_table_size);
staticint orangefs_devreq_open(struct inode *inode, struct file *file)
{ int ret = -EINVAL;
/* in order to ensure that the filesystem driver sees correct UIDs */ if (file->f_cred->user_ns != &init_user_ns) {
gossip_err("%s: device cannot be opened outside init_user_ns\n",
__func__); goto out;
}
if (!(file->f_flags & O_NONBLOCK)) {
gossip_err("%s: device cannot be opened in blocking mode\n",
__func__); goto out;
}
ret = -EACCES;
gossip_debug(GOSSIP_DEV_DEBUG, "client-core: opening device\n");
mutex_lock(&devreq_mutex);
if (open_access_count == 0) {
open_access_count = 1;
ret = 0;
} else {
DUMP_DEVICE_ERROR();
}
mutex_unlock(&devreq_mutex);
/* Function for read() callers into the device */ static ssize_t orangefs_devreq_read(struct file *file, char __user *buf,
size_t count, loff_t *offset)
{ struct orangefs_kernel_op_s *op, *temp;
__s32 proto_ver = ORANGEFS_KERNEL_PROTO_VERSION; static __s32 magic = ORANGEFS_DEVREQ_MAGIC; struct orangefs_kernel_op_s *cur_op; unsignedlong ret;
/* We do not support blocking IO. */ if (!(file->f_flags & O_NONBLOCK)) {
gossip_err("%s: blocking read from client-core.\n",
__func__); return -EINVAL;
}
/* *TheclientwilldoanioctltofindMAX_DEV_REQ_UPSIZE,then *alwaysreadwiththatsizebuffer.
*/ if (count != MAX_DEV_REQ_UPSIZE) {
gossip_err("orangefs: client-core tried to read wrong size\n"); return -EINVAL;
}
/* Check for an empty list before locking. */ if (list_empty(&orangefs_request_list)) return -EAGAIN;
restart:
cur_op = NULL; /* Get next op (if any) from top of list. */
spin_lock(&orangefs_request_list_lock);
list_for_each_entry_safe(op, temp, &orangefs_request_list, list) {
__s32 fsid; /* This lock is held past the end of the loop when we break. */
spin_lock(&op->lock); if (unlikely(op_state_purged(op) || op_state_given_up(op))) {
spin_unlock(&op->lock); continue;
}
fsid = fsid_of_op(op); if (fsid != ORANGEFS_FS_ID_NULL) { int ret; /* Skip ops whose filesystem needs to be mounted. */
ret = fs_mount_pending(fsid); if (ret == 1) {
gossip_debug(GOSSIP_DEV_DEBUG, "%s: mount pending, skipping op tag " "%llu %s\n",
__func__,
llu(op->tag),
get_opname_string(op));
spin_unlock(&op->lock); continue; /* *Skipopswhosefilesystemwedon'tknowaboutunless *itisbeingmountedorunmounted.Itispossiblefor *afilesystemwedon'tknowabouttobeunmountedif *itfailstomountinthekernelafteruserspacehas *beensentthemountrequest.
*/ /* XXX: is there a better way to detect this? */
} elseif (ret == -1 &&
!(op->upcall.type ==
ORANGEFS_VFS_OP_FS_MOUNT ||
op->upcall.type ==
ORANGEFS_VFS_OP_GETATTR ||
op->upcall.type ==
ORANGEFS_VFS_OP_FS_UMOUNT)) {
gossip_debug(GOSSIP_DEV_DEBUG, "orangefs: skipping op tag %llu %s\n",
llu(op->tag), get_opname_string(op));
gossip_err( "orangefs: ERROR: fs_mount_pending %d\n",
fsid);
spin_unlock(&op->lock); continue;
}
} /* *Eitherthisopdoesnotpertaintoafilesystem,ismounting *afilesystem,orpertainstoamountedfilesystem.Letit *through.
*/
cur_op = op; break;
}
if (total < MAX_DEV_REQ_DOWNSIZE) {
gossip_err("%s: total:%d: must be at least:%u:\n",
__func__,
total,
(unsignedint) MAX_DEV_REQ_DOWNSIZE); return -EFAULT;
}
if (!copy_from_iter_full(&head, head_size, iter)) {
gossip_err("%s: failed to copy head.\n", __func__); return -EFAULT;
}
if (head.version < ORANGEFS_MINIMUM_USERSPACE_VERSION) {
gossip_err("%s: userspace claims version" "%d, minimum version required: %d.\n",
__func__,
head.version,
ORANGEFS_MINIMUM_USERSPACE_VERSION); return -EPROTO;
}
if (head.magic != ORANGEFS_DEVREQ_MAGIC) {
gossip_err("Error: Device magic number does not match.\n"); return -EPROTO;
}
if (!orangefs_userspace_version) {
orangefs_userspace_version = head.version;
} elseif (orangefs_userspace_version != head.version) {
gossip_err("Error: userspace version changes\n"); return -EPROTO;
}
/* remove the op from the in progress hash table */
op = orangefs_devreq_remove_op(head.tag); if (!op) {
gossip_debug(GOSSIP_DEV_DEBUG, "%s: No one's waiting for tag %llu\n",
__func__, llu(head.tag)); return ret;
}
if (!copy_from_iter_full(&op->downcall, downcall_size, iter)) {
gossip_err("%s: failed to copy downcall.\n", __func__); goto Efault;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.