Release 4.11 net/9p/client.c
/*
* net/9p/clnt.c
*
* 9P Client
*
* Copyright (C) 2008 by Eric Van Hensbergen <ericvh@gmail.com>
* Copyright (C) 2007 by Latchesar Ionkov <lucho@ionkov.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to:
* Free Software Foundation
* 51 Franklin Street, Fifth Floor
* Boston, MA 02111-1301 USA
*
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/module.h>
#include <linux/errno.h>
#include <linux/fs.h>
#include <linux/poll.h>
#include <linux/idr.h>
#include <linux/mutex.h>
#include <linux/slab.h>
#include <linux/sched/signal.h>
#include <linux/uaccess.h>
#include <linux/uio.h>
#include <net/9p/9p.h>
#include <linux/parser.h>
#include <net/9p/client.h>
#include <net/9p/transport.h>
#include "protocol.h"
#define CREATE_TRACE_POINTS
#include <trace/events/9p.h>
/*
* Client Option Parsing (code inspired by NFS code)
* - a little lazy - parse all client options
*/
enum {
Opt_msize,
Opt_trans,
Opt_legacy,
Opt_version,
Opt_err,
};
static const match_table_t tokens = {
{Opt_msize, "msize=%u"},
{Opt_legacy, "noextend"},
{Opt_trans, "trans=%s"},
{Opt_version, "version=%s"},
{Opt_err, NULL},
};
inline int p9_is_proto_dotl(struct p9_client *clnt)
{
return clnt->proto_version == p9_proto_2000L;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Sripathi Kodi | 18 | 100.00% | 2 | 100.00% |
Total | 18 | 100.00% | 2 | 100.00% |
EXPORT_SYMBOL(p9_is_proto_dotl);
inline int p9_is_proto_dotu(struct p9_client *clnt)
{
return clnt->proto_version == p9_proto_2000u;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Sripathi Kodi | 18 | 100.00% | 1 | 100.00% |
Total | 18 | 100.00% | 1 | 100.00% |
EXPORT_SYMBOL(p9_is_proto_dotu);
/*
* Some error codes are taken directly from the server replies,
* make sure they are valid.
*/
static int safe_errno(int err)
{
if ((err > 0) || (err < -MAX_ERRNO)) {
p9_debug(P9_DEBUG_ERROR, "Invalid error code %d\n", err);
return -EPROTO;
}
return err;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Simon Derr | 42 | 100.00% | 1 | 100.00% |
Total | 42 | 100.00% | 1 | 100.00% |
/* Interpret mount option for protocol version */
static int get_protocol_version(char *s)
{
int version = -EINVAL;
if (!strcmp(s, "9p2000")) {
version = p9_proto_legacy;
p9_debug(P9_DEBUG_9P, "Protocol version: Legacy\n");
} else if (!strcmp(s, "9p2000.u")) {
version = p9_proto_2000u;
p9_debug(P9_DEBUG_9P, "Protocol version: 9P2000.u\n");
} else if (!strcmp(s, "9p2000.L")) {
version = p9_proto_2000L;
p9_debug(P9_DEBUG_9P, "Protocol version: 9P2000.L\n");
} else
pr_info("Unknown protocol version %s\n", s);
return version;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Sripathi Kodi | 79 | 80.61% | 2 | 40.00% |
Prem Karat | 12 | 12.24% | 1 | 20.00% |
Joe Perches | 5 | 5.10% | 1 | 20.00% |
Dan Carpenter | 2 | 2.04% | 1 | 20.00% |
Total | 98 | 100.00% | 5 | 100.00% |
/**
* parse_options - parse mount options into client structure
* @opts: options string passed from mount
* @clnt: existing v9fs client information
*
* Return 0 upon success, -ERRNO upon failure
*/
static int parse_opts(char *opts, struct p9_client *clnt)
{
char *options, *tmp_options;
char *p;
substring_t args[MAX_OPT_ARGS];
int option;
char *s;
int ret = 0;
clnt->proto_version = p9_proto_2000L;
clnt->msize = 8192;
if (!opts)
return 0;
tmp_options = kstrdup(opts, GFP_KERNEL);
if (!tmp_options) {
p9_debug(P9_DEBUG_ERROR,
"failed to allocate copy of option string\n");
return -ENOMEM;
}
options = tmp_options;
while ((p = strsep(&options, ",")) != NULL) {
int token, r;
if (!*p)
continue;
token = match_token(p, tokens, args);
switch (token) {
case Opt_msize:
r = match_int(&args[0], &option);
if (r < 0) {
p9_debug(P9_DEBUG_ERROR,
"integer field, but no integer?\n");
ret = r;
continue;
}
clnt->msize = option;
break;
case Opt_trans:
s = match_strdup(&args[0]);
if (!s) {
ret = -ENOMEM;
p9_debug(P9_DEBUG_ERROR,
"problem allocating copy of trans arg\n");
goto free_and_return;
}
clnt->trans_mod = v9fs_get_trans_by_name(s);
if (clnt->trans_mod == NULL) {
pr_info("Could not find request transport: %s\n",
s);
ret = -EINVAL;
kfree(s);
goto free_and_return;
}
kfree(s);
break;
case Opt_legacy:
clnt->proto_version = p9_proto_legacy;
break;
case Opt_version:
s = match_strdup(&args[0]);
if (!s) {
ret = -ENOMEM;
p9_debug(P9_DEBUG_ERROR,
"problem allocating copy of version arg\n");
goto free_and_return;
}
ret = get_protocol_version(s);
if (ret == -EINVAL) {
kfree(s);
goto free_and_return;
}
kfree(s);
clnt->proto_version = ret;
break;
default:
continue;
}
}
free_and_return:
kfree(tmp_options);
return ret;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Eric Van Hensbergen | 225 | 62.33% | 4 | 40.00% |
Prem Karat | 89 | 24.65% | 1 | 10.00% |
Sripathi Kodi | 32 | 8.86% | 2 | 20.00% |
Aneesh Kumar K.V | 9 | 2.49% | 2 | 20.00% |
Joe Perches | 6 | 1.66% | 1 | 10.00% |
Total | 361 | 100.00% | 10 | 100.00% |
static struct p9_fcall *p9_fcall_alloc(int alloc_msize)
{
struct p9_fcall *fc;
fc = kmalloc(sizeof(struct p9_fcall) + alloc_msize, GFP_NOFS);
if (!fc)
return NULL;
fc->capacity = alloc_msize;
fc->sdata = (char *) fc + sizeof(struct p9_fcall);
return fc;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Simon Derr | 63 | 98.44% | 1 | 50.00% |
Rashika Kheria | 1 | 1.56% | 1 | 50.00% |
Total | 64 | 100.00% | 2 | 100.00% |
/**
* p9_tag_alloc - lookup/allocate a request by tag
* @c: client session to lookup tag within
* @tag: numeric id for transaction
*
* this is a simple array lookup, but will grow the
* request_slots as necessary to accommodate transaction
* ids which did not previously have a slot.
*
* this code relies on the client spinlock to manage locks, its
* possible we should switch to something else, but I'd rather
* stick with something low-overhead for the common case.
*
*/
static struct p9_req_t *
p9_tag_alloc(struct p9_client *c, u16 tag, unsigned int max_size)
{
unsigned long flags;
int row, col;
struct p9_req_t *req;
int alloc_msize = min(c->msize, max_size);
/* This looks up the original request by tag so we know which
* buffer to read the data into */
tag++;
if (tag >= c->max_tag) {
spin_lock_irqsave(&c->lock, flags);
/* check again since original check was outside of lock */
while (tag >= c->max_tag) {
row = (tag / P9_ROW_MAXTAG);
c->reqs[row] = kcalloc(P9_ROW_MAXTAG,
sizeof(struct p9_req_t), GFP_ATOMIC);
if (!c->reqs[row]) {
pr_err("Couldn't grow tag array\n");
spin_unlock_irqrestore(&c->lock, flags);
return ERR_PTR(-ENOMEM);
}
for (col = 0; col < P9_ROW_MAXTAG; col++) {
c->reqs[row][col].status = REQ_STATUS_IDLE;
c->reqs[row][col].tc = NULL;
}
c->max_tag += P9_ROW_MAXTAG;
}
spin_unlock_irqrestore(&c->lock, flags);
}
row = tag / P9_ROW_MAXTAG;
col = tag % P9_ROW_MAXTAG;
req = &c->reqs[row][col];
if (!req->wq) {
req->wq = kmalloc(sizeof(wait_queue_head_t), GFP_NOFS);
if (!req->wq)
goto grow_failed;
init_waitqueue_head(req->wq);
}
if (!req->tc)
req->tc = p9_fcall_alloc(alloc_msize);
if (!req->rc)
req->rc = p9_fcall_alloc(alloc_msize);
if (!req->tc || !req->rc)
goto grow_failed;
p9pdu_reset(req->tc);
p9pdu_reset(req->rc);
req->tc->tag = tag-1;
req->status = REQ_STATUS_ALLOC;
return req;
grow_failed:
pr_err("Couldn't grow tag array\n");
kfree(req->tc);
kfree(req->rc);
kfree(req->wq);
req->tc = req->rc = NULL;
req->wq = NULL;
return ERR_PTR(-ENOMEM);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Eric Van Hensbergen | 292 | 73.37% | 3 | 30.00% |
Simon Derr | 82 | 20.60% | 2 | 20.00% |
Aneesh Kumar K.V | 16 | 4.02% | 2 | 20.00% |
Dan Carpenter | 7 | 1.76% | 2 | 20.00% |
Joe Perches | 1 | 0.25% | 1 | 10.00% |
Total | 398 | 100.00% | 10 | 100.00% |
/**
* p9_tag_lookup - lookup a request by tag
* @c: client session to lookup tag within
* @tag: numeric id for transaction
*
*/
struct p9_req_t *p9_tag_lookup(struct p9_client *c, u16 tag)
{
int row, col;
/* This looks up the original request by tag so we know which
* buffer to read the data into */
tag++;
if(tag >= c->max_tag)
return NULL;
row = tag / P9_ROW_MAXTAG;
col = tag % P9_ROW_MAXTAG;
return &c->reqs[row][col];
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Eric Van Hensbergen | 59 | 100.00% | 2 | 100.00% |
Total | 59 | 100.00% | 2 | 100.00% |
EXPORT_SYMBOL(p9_tag_lookup);
/**
* p9_tag_init - setup tags structure and contents
* @c: v9fs client struct
*
* This initializes the tags structure for each client instance.
*
*/
static int p9_tag_init(struct p9_client *c)
{
int err = 0;
c->tagpool = p9_idpool_create();
if (IS_ERR(c->tagpool)) {
err = PTR_ERR(c->tagpool);
goto error;
}
err = p9_idpool_get(c->tagpool); /* reserve tag 0 */
if (err < 0) {
p9_idpool_destroy(c->tagpool);
goto error;
}
c->max_tag = 0;
error:
return err;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Eric Van Hensbergen | 65 | 76.47% | 1 | 50.00% |
Aneesh Kumar K.V | 20 | 23.53% | 1 | 50.00% |
Total | 85 | 100.00% | 2 | 100.00% |
/**
* p9_tag_cleanup - cleans up tags structure and reclaims resources
* @c: v9fs client struct
*
* This frees resources associated with the tags structure
*
*/
static void p9_tag_cleanup(struct p9_client *c)
{
int row, col;
/* check to insure all requests are idle */
for (row = 0; row < (c->max_tag/P9_ROW_MAXTAG); row++) {
for (col = 0; col < P9_ROW_MAXTAG; col++) {
if (c->reqs[row][col].status != REQ_STATUS_IDLE) {
p9_debug(P9_DEBUG_MUX,
"Attempting to cleanup non-free tag %d,%d\n",
row, col);
/* TODO: delay execution of cleanup */
return;
}
}
}
if (c->tagpool) {
p9_idpool_put(0, c->tagpool); /* free reserved tag 0 */
p9_idpool_destroy(c->tagpool);
}
/* free requests associated with tags */
for (row = 0; row < (c->max_tag/P9_ROW_MAXTAG); row++) {
for (col = 0; col < P9_ROW_MAXTAG; col++) {
kfree(c->reqs[row][col].wq);
kfree(c->reqs[row][col].tc);
kfree(c->reqs[row][col].rc);
}
kfree(c->reqs[row]);
}
c->max_tag = 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Eric Van Hensbergen | 194 | 93.72% | 3 | 60.00% |
Latchesar Ionkov | 12 | 5.80% | 1 | 20.00% |
Joe Perches | 1 | 0.48% | 1 | 20.00% |
Total | 207 | 100.00% | 5 | 100.00% |
/**
* p9_free_req - free a request and clean-up as necessary
* c: client state
* r: request to release
*
*/
static void p9_free_req(struct p9_client *c, struct p9_req_t *r)
{
int tag = r->tc->tag;
p9_debug(P9_DEBUG_MUX, "clnt %p req %p tag: %d\n", c, r, tag);
r->status = REQ_STATUS_IDLE;
if (tag != P9_NOTAG && p9_idpool_check(tag, c->tagpool))
p9_idpool_put(tag, c->tagpool);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Eric Van Hensbergen | 67 | 98.53% | 2 | 66.67% |
Joe Perches | 1 | 1.47% | 1 | 33.33% |
Total | 68 | 100.00% | 3 | 100.00% |
/**
* p9_client_cb - call back from transport to client
* c: client state
* req: request received
*
*/
void p9_client_cb(struct p9_client *c, struct p9_req_t *req, int status)
{
p9_debug(P9_DEBUG_MUX, " tag %d\n", req->tc->tag);
/*
* This barrier is needed to make sure any change made to req before
* the other thread wakes up will indeed be seen by the waiting side.
*/
smp_wmb();
req->status = status;
wake_up(req->wq);
p9_debug(P9_DEBUG_MUX, "wakeup: %d\n", req->tc->tag);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Eric Van Hensbergen | 43 | 70.49% | 4 | 57.14% |
Dominique Martinet | 13 | 21.31% | 1 | 14.29% |
Latchesar Ionkov | 3 | 4.92% | 1 | 14.29% |
Joe Perches | 2 | 3.28% | 1 | 14.29% |
Total | 61 | 100.00% | 7 | 100.00% |
EXPORT_SYMBOL(p9_client_cb);
/**
* p9_parse_header - parse header arguments out of a packet
* @pdu: packet to parse
* @size: size of packet
* @type: type of request
* @tag: tag of packet
* @rewind: set if we need to rewind offset afterwards
*/
int
p9_parse_header(struct p9_fcall *pdu, int32_t *size, int8_t *type, int16_t *tag,
int rewind)
{
int8_t r_type;
int16_t r_tag;
int32_t r_size;
int offset = pdu->offset;
int err;
pdu->offset = 0;
if (pdu->size == 0)
pdu->size = 7;
err = p9pdu_readf(pdu, 0, "dbw", &r_size, &r_type, &r_tag);
if (err)
goto rewind_and_exit;
pdu->size = r_size;
pdu->id = r_type;
pdu->tag = r_tag;
p9_debug(P9_DEBUG_9P, "<<< size=%d type: %d tag: %d\n",
pdu->size, pdu->id, pdu->tag);
if (type)
*type = r_type;
if (tag)
*tag = r_tag;
if (size)
*size = r_size;
rewind_and_exit:
if (rewind)
pdu->offset = offset;
return err;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Eric Van Hensbergen | 169 | 99.41% | 3 | 75.00% |
Joe Perches | 1 | 0.59% | 1 | 25.00% |
Total | 170 | 100.00% | 4 | 100.00% |
EXPORT_SYMBOL(p9_parse_header);
/**
* p9_check_errors - check 9p packet for error return and process it
* @c: current client instance
* @req: request to parse and check for error conditions
*
* returns error code if one is discovered, otherwise returns 0
*
* this will have to be more complicated if we have multiple
* error packet types
*/
static int p9_check_errors(struct p9_client *c, struct p9_req_t *req)
{
int8_t type;
int err;
int ecode;
err = p9_parse_header(req->rc, NULL, &type, NULL, 0);
/*
* dump the response from server
* This should be after check errors which poplulate pdu_fcall.
*/
trace_9p_protocol_dump(c, req->rc);
if (err) {
p9_debug(P9_DEBUG_ERROR, "couldn't parse header %d\n", err);
return err;
}
if (type != P9_RERROR && type != P9_RLERROR)
return 0;
if (!p9_is_proto_dotl(c)) {
char *ename;
err = p9pdu_readf(req->rc, c->proto_version, "s?d",
&ename, &ecode);
if (err)
goto out_err;
if (p9_is_proto_dotu(c) && ecode < 512)
err = -ecode;
if (!err) {
err = p9_errstr2errno(ename, strlen(ename));
p9_debug(P9_DEBUG_9P, "<<< RERROR (%d) %s\n",
-ecode, ename);
}
kfree(ename);
} else {
err = p9pdu_readf(req->rc, c->proto_version, "d", &ecode);
err = -ecode;
p9_debug(P9_DEBUG_9P, "<<< RLERROR (%d)\n", -ecode);
}
return err;
out_err:
p9_debug(P9_DEBUG_ERROR, "couldn't parse error%d\n", err);
return err;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Eric Van Hensbergen | 136 | 58.87% | 2 | 22.22% |
Arun R Bharadwaj | 63 | 27.27% | 1 | 11.11% |
Aneesh Kumar K.V | 11 | 4.76% | 2 | 22.22% |
Venkateswararao Jujjuri (JV) | 9 | 3.90% | 1 | 11.11% |
Joe Perches | 4 | 1.73% | 1 | 11.11% |
Sripathi Kodi | 4 | 1.73% | 1 | 11.11% |
Arnd Bergmann | 4 | 1.73% | 1 | 11.11% |
Total | 231 | 100.00% | 9 | 100.00% |
/**
* p9_check_zc_errors - check 9p packet for error return and process it
* @c: current client instance
* @req: request to parse and check for error conditions
* @in_hdrlen: Size of response protocol buffer.
*
* returns error code if one is discovered, otherwise returns 0
*
* this will have to be more complicated if we have multiple
* error packet types
*/
static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
struct iov_iter *uidata, int in_hdrlen)
{
int err;
int ecode;
int8_t type;
char *ename = NULL;
err = p9_parse_header(req->rc, NULL, &type, NULL, 0);
/*
* dump the response from server
* This should be after parse_header which poplulate pdu_fcall.
*/
trace_9p_protocol_dump(c, req->rc);
if (err) {
p9_debug(P9_DEBUG_ERROR, "couldn't parse header %d\n", err);
return err;
}
if (type != P9_RERROR && type != P9_RLERROR)
return 0;
if (!p9_is_proto_dotl(c)) {
/* Error is reported in string format */
int len;
/* 7 = header size for RERROR; */
int inline_len = in_hdrlen - 7;
len = req->rc->size - req->rc->offset;
if (len > (P9_ZC_HDR_SZ - 7)) {
err = -EFAULT;
goto out_err;
}
ename = &req->rc->sdata[req->rc->offset];
if (len > inline_len) {
/* We have error in external buffer */
err = copy_from_iter(ename + inline_len,
len - inline_len, uidata);
if (err != len - inline_len) {
err = -EFAULT;
goto out_err;
}
}
ename = NULL;
err = p9pdu_readf(req->rc, c->proto_version, "s?d",
&ename, &ecode);
if (err)
goto out_err;
if (p9_is_proto_dotu(c) && ecode < 512)
err = -ecode;
if (!err) {
err = p9_errstr2errno(ename, strlen(ename));
p9_debug(P9_DEBUG_9P, "<<< RERROR (%d) %s\n",
-ecode, ename);
}
kfree(ename);
} else {
err = p9pdu_readf(req->rc, c->proto_version, "d", &ecode);
err = -ecode;
p9_debug(P9_DEBUG_9P, "<<< RLERROR (%d)\n", -ecode);
}
return err;
out_err:
p9_debug(P9_DEBUG_ERROR, "couldn't parse error%d\n", err);
return err;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Aneesh Kumar K.V | 291 | 83.38% | 3 | 37.50% |
Eric Van Hensbergen | 41 | 11.75% | 2 | 25.00% |
Al Viro | 9 | 2.58% | 1 | 12.50% |
Joe Perches | 4 | 1.15% | 1 | 12.50% |
Arnd Bergmann | 4 | 1.15% | 1 | 12.50% |
Total | 349 | 100.00% | 8 | 100.00% |
static struct p9_req_t *
p9_client_rpc(struct p9_client *c, int8_t type, const char *fmt, ...);
/**
* p9_client_flush - flush (cancel) a request
* @c: client state
* @oldreq: request to cancel
*
* This sents a flush for a particular request and links
* the flush request to the original request. The current
* code only supports a single flush request although the protocol
* allows for multiple flush requests to be sent for a single request.
*
*/
static int p9_client_flush(struct p9_client *c, struct p9_req_t *oldreq)
{
struct p9_req_t *req;
int16_t oldtag;
int err;
err = p9_parse_header(oldreq->tc, NULL, NULL, &oldtag, 1);
if (err)
return err;
p9_debug(P9_DEBUG_9P, ">>> TFLUSH tag %d\n", oldtag);
req = p9_client_rpc(c, P9_TFLUSH, "w", oldtag);
if (IS_ERR(req))
return PTR_ERR(req);
/*
* if we haven't received a response for oldreq,
* remove it from the list
*/
if (oldreq->status == REQ_STATUS_SENT)
if (c->trans_mod->cancelled)
c->trans_mod->cancelled(c, oldreq);
p9_free_req(c, req);
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Aneesh Kumar K.V | 105 | 84.00% | 1 | 16.67% |
Simon Derr | 17 | 13.60% | 3 | 50.00% |
Andi Shyti | 2 | 1.60% | 1 | 16.67% |
Joe Perches | 1 | 0.80% | 1 | 16.67% |
Total | 125 | 100.00% | 6 | 100.00% |
static struct p9_req_t *p9_client_prepare_req(struct p9_client *c,
int8_t type, int req_size,
const char *fmt, va_list ap)
{
int tag, err;
struct p9_req_t *req;
p9_debug(P9_DEBUG_MUX, "client %p op %d\n", c, type);
/* we allow for any status other than disconnected */
if (c->status == Disconnected)
return ERR_PTR(-EIO);
/* if status is begin_disconnected we allow only clunk request */
if ((c->status == BeginDisconnect) && (type != P9_TCLUNK))
return ERR_PTR(-EIO);
tag = P9_NOTAG;
if (type != P9_TVERSION) {
tag = p9_idpool_get(c->tagpool);
if (tag < 0)
return ERR_PTR(-ENOMEM);
}
req = p9_tag_alloc(c, tag, req_size);
if (IS_ERR(req))
return req;
/* marshall the data */
p9pdu_prepare(req->tc, tag, type);
err = p9pdu_vwritef(req->tc, c->proto_version, fmt, ap);
if (err)
goto reterr;
p9pdu_finalize(c, req->tc);
trace_9p_client_req(c, type, tag);
return req;
reterr:
p9_free_req(c, req);
return ERR_PTR(err);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Aneesh Kumar K.V | 214 | 99.53% | 2 | 66.67% |
Joe Perches | 1 | 0.47% | 1 | 33.33% |
Total | 215 | 100.00% | 3 | 100.00% |
/**
* p9_client_rpc - issue a request and wait for a response
* @c: client session
* @type: type of request
* @fmt: protocol format string (see protocol.c)
*
* Returns request structure (which client must free using p9_free_req)
*/
static struct p9_req_t *
p9_client_rpc(struct p9_client *c, int8_t type, const char *fmt, ...)
{
va_list ap;
int sigpending, err;
unsigned long flags;
struct p9_req_t *req;
va_start(ap, fmt);
req = p9_client_prepare_req(c, type, c->msize, fmt, ap);
va_end(ap);
if (IS_ERR(req))
return req;
if (signal_pending(current)) {
sigpending = 1;
clear_thread_flag(TIF_SIGPENDING);
} else
sigpending = 0;
err = c->trans_mod->request(c, req);
if (err < 0) {
if (err != -ERESTARTSYS && err != -EFAULT)
c->status = Disconnected;
goto reterr;
}
again:
/* Wait for the response */
err = wait_event_interruptible(*req->wq,
req->status >= REQ_STATUS_RCVD);
/*
* Make sure our req is coherent with regard to updates in other
* threads - echoes to wmb() in the callback
*/
smp_rmb();
if ((err == -ERESTARTSYS) && (c->status == Connected)
&& (type == P9_TFLUSH)) {
sigpending = 1;
clear_thread_flag(TIF_SIGPENDING);
goto again;
}
if (req->status == REQ_STATUS_ERROR) {
p9_debug(P9_DEBUG_ERROR, "req_status error %d\n", req->t_err);
err = req->t_err;
}
if ((err == -ERESTARTSYS) && (c->status == Connected