Commit ebbe7887 authored by Trond Myklebust's avatar Trond Myklebust

SUNRPC: Don't return error values in sysfs read of closed files

Instead of returning an error value, which ends up being the return
value for the read() system call, it is more elegant to simply return
the error as a string value.
Signed-off-by: default avatarTrond Myklebust <trond.myklebust@hammerspace.com>
parent 421ab1be
...@@ -93,10 +93,13 @@ static ssize_t rpc_sysfs_xprt_dstaddr_show(struct kobject *kobj, ...@@ -93,10 +93,13 @@ static ssize_t rpc_sysfs_xprt_dstaddr_show(struct kobject *kobj,
struct rpc_xprt *xprt = rpc_sysfs_xprt_kobj_get_xprt(kobj); struct rpc_xprt *xprt = rpc_sysfs_xprt_kobj_get_xprt(kobj);
ssize_t ret; ssize_t ret;
if (!xprt) if (!xprt) {
return 0; ret = sprintf(buf, "<closed>\n");
goto out;
}
ret = sprintf(buf, "%s\n", xprt->address_strings[RPC_DISPLAY_ADDR]); ret = sprintf(buf, "%s\n", xprt->address_strings[RPC_DISPLAY_ADDR]);
xprt_put(xprt); xprt_put(xprt);
out:
return ret; return ret;
} }
...@@ -106,10 +109,10 @@ static ssize_t rpc_sysfs_xprt_srcaddr_show(struct kobject *kobj, ...@@ -106,10 +109,10 @@ static ssize_t rpc_sysfs_xprt_srcaddr_show(struct kobject *kobj,
{ {
struct rpc_xprt *xprt = rpc_sysfs_xprt_kobj_get_xprt(kobj); struct rpc_xprt *xprt = rpc_sysfs_xprt_kobj_get_xprt(kobj);
size_t buflen = PAGE_SIZE; size_t buflen = PAGE_SIZE;
ssize_t ret = -ENOTSOCK; ssize_t ret;
if (!xprt || !xprt_connected(xprt)) { if (!xprt || !xprt_connected(xprt)) {
ret = -ENOTCONN; ret = sprintf(buf, "<closed>\n");
} else if (xprt->ops->get_srcaddr) { } else if (xprt->ops->get_srcaddr) {
ret = xprt->ops->get_srcaddr(xprt, buf, buflen); ret = xprt->ops->get_srcaddr(xprt, buf, buflen);
if (ret > 0) { if (ret > 0) {
...@@ -118,8 +121,10 @@ static ssize_t rpc_sysfs_xprt_srcaddr_show(struct kobject *kobj, ...@@ -118,8 +121,10 @@ static ssize_t rpc_sysfs_xprt_srcaddr_show(struct kobject *kobj,
ret++; ret++;
buf[ret] = '\0'; buf[ret] = '\0';
} }
} } else
} ret = sprintf(buf, "<closed>\n");
} else
ret = sprintf(buf, "<not a socket>\n");
xprt_put(xprt); xprt_put(xprt);
return ret; return ret;
} }
...@@ -133,8 +138,8 @@ static ssize_t rpc_sysfs_xprt_info_show(struct kobject *kobj, ...@@ -133,8 +138,8 @@ static ssize_t rpc_sysfs_xprt_info_show(struct kobject *kobj,
ssize_t ret; ssize_t ret;
if (!xprt || !xprt_connected(xprt)) { if (!xprt || !xprt_connected(xprt)) {
xprt_put(xprt); ret = sprintf(buf, "<closed>\n");
return -ENOTCONN; goto out;
} }
if (xprt->ops->get_srcport) if (xprt->ops->get_srcport)
...@@ -152,6 +157,7 @@ static ssize_t rpc_sysfs_xprt_info_show(struct kobject *kobj, ...@@ -152,6 +157,7 @@ static ssize_t rpc_sysfs_xprt_info_show(struct kobject *kobj,
xprt->backlog.qlen, xprt->main, srcport, xprt->backlog.qlen, xprt->main, srcport,
atomic_long_read(&xprt->queuelen), atomic_long_read(&xprt->queuelen),
xprt->address_strings[RPC_DISPLAY_PORT]); xprt->address_strings[RPC_DISPLAY_PORT]);
out:
xprt_put(xprt); xprt_put(xprt);
return ret; return ret;
} }
...@@ -165,10 +171,7 @@ static ssize_t rpc_sysfs_xprt_state_show(struct kobject *kobj, ...@@ -165,10 +171,7 @@ static ssize_t rpc_sysfs_xprt_state_show(struct kobject *kobj,
int locked, connected, connecting, close_wait, bound, binding, int locked, connected, connecting, close_wait, bound, binding,
closing, congested, cwnd_wait, write_space, offline, remove; closing, congested, cwnd_wait, write_space, offline, remove;
if (!xprt) if (!(xprt && xprt->state)) {
return 0;
if (!xprt->state) {
ret = sprintf(buf, "state=CLOSED\n"); ret = sprintf(buf, "state=CLOSED\n");
} else { } else {
locked = test_bit(XPRT_LOCKED, &xprt->state); locked = test_bit(XPRT_LOCKED, &xprt->state);
......
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