Commit 067c054f authored by Al Viro's avatar Al Viro

dlmfs: clean up dlmfs_file_{read,write}() a bit

The damn file is constant-sized - 64 bytes.  IOW,
	* i_size_read() is pointless
	* so's dynamic allocation
	* so's the 'size' argument of user_dlm_read_lvb()
	* ... and so's open-coding simple_read_from_buffer(), while we are at it.
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent b3a9e3b9
...@@ -221,47 +221,17 @@ static __poll_t dlmfs_file_poll(struct file *file, poll_table *wait) ...@@ -221,47 +221,17 @@ static __poll_t dlmfs_file_poll(struct file *file, poll_table *wait)
return event; return event;
} }
static ssize_t dlmfs_file_read(struct file *filp, static ssize_t dlmfs_file_read(struct file *file,
char __user *buf, char __user *buf,
size_t count, size_t count,
loff_t *ppos) loff_t *ppos)
{ {
int bytes_left; char lvb[DLM_LVB_LEN];
ssize_t got;
char *lvb_buf;
struct inode *inode = file_inode(filp);
mlog(0, "inode %lu, count = %zu, *ppos = %llu\n",
inode->i_ino, count, *ppos);
if (*ppos >= i_size_read(inode)) if (!user_dlm_read_lvb(file_inode(file), lvb))
return 0; return 0;
/* don't read past the lvb */ return simple_read_from_buffer(buf, count, ppos, lvb, sizeof(lvb));
if (count > i_size_read(inode) - *ppos)
count = i_size_read(inode) - *ppos;
if (!count)
return 0;
lvb_buf = kmalloc(count, GFP_NOFS);
if (!lvb_buf)
return -ENOMEM;
got = user_dlm_read_lvb(inode, lvb_buf, count);
if (got) {
BUG_ON(got != count);
bytes_left = copy_to_user(buf, lvb_buf, count);
count -= bytes_left;
} else
count = 0;
kfree(lvb_buf);
*ppos = *ppos + count;
mlog(0, "read %zu bytes\n", count);
return count;
} }
static ssize_t dlmfs_file_write(struct file *filp, static ssize_t dlmfs_file_write(struct file *filp,
...@@ -269,34 +239,28 @@ static ssize_t dlmfs_file_write(struct file *filp, ...@@ -269,34 +239,28 @@ static ssize_t dlmfs_file_write(struct file *filp,
size_t count, size_t count,
loff_t *ppos) loff_t *ppos)
{ {
char lvb_buf[DLM_LVB_LEN];
int bytes_left; int bytes_left;
char *lvb_buf;
struct inode *inode = file_inode(filp); struct inode *inode = file_inode(filp);
mlog(0, "inode %lu, count = %zu, *ppos = %llu\n", mlog(0, "inode %lu, count = %zu, *ppos = %llu\n",
inode->i_ino, count, *ppos); inode->i_ino, count, *ppos);
if (*ppos >= i_size_read(inode)) if (*ppos >= DLM_LVB_LEN)
return -ENOSPC; return -ENOSPC;
/* don't write past the lvb */ /* don't write past the lvb */
if (count > i_size_read(inode) - *ppos) if (count > DLM_LVB_LEN - *ppos)
count = i_size_read(inode) - *ppos; count = DLM_LVB_LEN - *ppos;
if (!count) if (!count)
return 0; return 0;
lvb_buf = kmalloc(count, GFP_NOFS);
if (!lvb_buf)
return -ENOMEM;
bytes_left = copy_from_user(lvb_buf, buf, count); bytes_left = copy_from_user(lvb_buf, buf, count);
count -= bytes_left; count -= bytes_left;
if (count) if (count)
user_dlm_write_lvb(inode, lvb_buf, count); user_dlm_write_lvb(inode, lvb_buf, count);
kfree(lvb_buf);
*ppos = *ppos + count; *ppos = *ppos + count;
mlog(0, "wrote %zu bytes\n", count); mlog(0, "wrote %zu bytes\n", count);
return count; return count;
......
...@@ -547,24 +547,20 @@ void user_dlm_write_lvb(struct inode *inode, ...@@ -547,24 +547,20 @@ void user_dlm_write_lvb(struct inode *inode,
spin_unlock(&lockres->l_lock); spin_unlock(&lockres->l_lock);
} }
ssize_t user_dlm_read_lvb(struct inode *inode, bool user_dlm_read_lvb(struct inode *inode, char *val)
char *val,
unsigned int len)
{ {
struct user_lock_res *lockres = &DLMFS_I(inode)->ip_lockres; struct user_lock_res *lockres = &DLMFS_I(inode)->ip_lockres;
char *lvb; char *lvb;
ssize_t ret = len; bool ret = true;
BUG_ON(len > DLM_LVB_LEN);
spin_lock(&lockres->l_lock); spin_lock(&lockres->l_lock);
BUG_ON(lockres->l_level < DLM_LOCK_PR); BUG_ON(lockres->l_level < DLM_LOCK_PR);
if (ocfs2_dlm_lvb_valid(&lockres->l_lksb)) { if (ocfs2_dlm_lvb_valid(&lockres->l_lksb)) {
lvb = ocfs2_dlm_lvb(&lockres->l_lksb); lvb = ocfs2_dlm_lvb(&lockres->l_lksb);
memcpy(val, lvb, len); memcpy(val, lvb, DLM_LVB_LEN);
} else } else
ret = 0; ret = false;
spin_unlock(&lockres->l_lock); spin_unlock(&lockres->l_lock);
return ret; return ret;
......
...@@ -66,9 +66,7 @@ void user_dlm_cluster_unlock(struct user_lock_res *lockres, ...@@ -66,9 +66,7 @@ void user_dlm_cluster_unlock(struct user_lock_res *lockres,
void user_dlm_write_lvb(struct inode *inode, void user_dlm_write_lvb(struct inode *inode,
const char *val, const char *val,
unsigned int len); unsigned int len);
ssize_t user_dlm_read_lvb(struct inode *inode, bool user_dlm_read_lvb(struct inode *inode, char *val);
char *val,
unsigned int len);
struct ocfs2_cluster_connection *user_dlm_register(const struct qstr *name); struct ocfs2_cluster_connection *user_dlm_register(const struct qstr *name);
void user_dlm_unregister(struct ocfs2_cluster_connection *conn); void user_dlm_unregister(struct ocfs2_cluster_connection *conn);
void user_dlm_set_locking_protocol(void); void user_dlm_set_locking_protocol(void);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment