2016-06-29 13:47:03 +02:00
|
|
|
#ifndef QEMU_9P_H
|
|
|
|
#define QEMU_9P_H
|
2016-01-07 19:18:02 +01:00
|
|
|
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <utime.h>
|
|
|
|
#include <sys/resource.h>
|
|
|
|
#include "fsdev/file-op-9p.h"
|
|
|
|
#include "fsdev/9p-iov-marshal.h"
|
|
|
|
#include "qemu/thread.h"
|
|
|
|
#include "qemu/coroutine.h"
|
2019-10-10 11:36:05 +02:00
|
|
|
#include "qemu/qht.h"
|
2016-01-07 19:18:02 +01:00
|
|
|
|
|
|
|
enum {
|
|
|
|
P9_TLERROR = 6,
|
|
|
|
P9_RLERROR,
|
|
|
|
P9_TSTATFS = 8,
|
|
|
|
P9_RSTATFS,
|
|
|
|
P9_TLOPEN = 12,
|
|
|
|
P9_RLOPEN,
|
|
|
|
P9_TLCREATE = 14,
|
|
|
|
P9_RLCREATE,
|
|
|
|
P9_TSYMLINK = 16,
|
|
|
|
P9_RSYMLINK,
|
|
|
|
P9_TMKNOD = 18,
|
|
|
|
P9_RMKNOD,
|
|
|
|
P9_TRENAME = 20,
|
|
|
|
P9_RRENAME,
|
|
|
|
P9_TREADLINK = 22,
|
|
|
|
P9_RREADLINK,
|
|
|
|
P9_TGETATTR = 24,
|
|
|
|
P9_RGETATTR,
|
|
|
|
P9_TSETATTR = 26,
|
|
|
|
P9_RSETATTR,
|
|
|
|
P9_TXATTRWALK = 30,
|
|
|
|
P9_RXATTRWALK,
|
|
|
|
P9_TXATTRCREATE = 32,
|
|
|
|
P9_RXATTRCREATE,
|
|
|
|
P9_TREADDIR = 40,
|
|
|
|
P9_RREADDIR,
|
|
|
|
P9_TFSYNC = 50,
|
|
|
|
P9_RFSYNC,
|
|
|
|
P9_TLOCK = 52,
|
|
|
|
P9_RLOCK,
|
|
|
|
P9_TGETLOCK = 54,
|
|
|
|
P9_RGETLOCK,
|
|
|
|
P9_TLINK = 70,
|
|
|
|
P9_RLINK,
|
|
|
|
P9_TMKDIR = 72,
|
|
|
|
P9_RMKDIR,
|
|
|
|
P9_TRENAMEAT = 74,
|
|
|
|
P9_RRENAMEAT,
|
|
|
|
P9_TUNLINKAT = 76,
|
|
|
|
P9_RUNLINKAT,
|
|
|
|
P9_TVERSION = 100,
|
|
|
|
P9_RVERSION,
|
|
|
|
P9_TAUTH = 102,
|
|
|
|
P9_RAUTH,
|
|
|
|
P9_TATTACH = 104,
|
|
|
|
P9_RATTACH,
|
|
|
|
P9_TERROR = 106,
|
|
|
|
P9_RERROR,
|
|
|
|
P9_TFLUSH = 108,
|
|
|
|
P9_RFLUSH,
|
|
|
|
P9_TWALK = 110,
|
|
|
|
P9_RWALK,
|
|
|
|
P9_TOPEN = 112,
|
|
|
|
P9_ROPEN,
|
|
|
|
P9_TCREATE = 114,
|
|
|
|
P9_RCREATE,
|
|
|
|
P9_TREAD = 116,
|
|
|
|
P9_RREAD,
|
|
|
|
P9_TWRITE = 118,
|
|
|
|
P9_RWRITE,
|
|
|
|
P9_TCLUNK = 120,
|
|
|
|
P9_RCLUNK,
|
|
|
|
P9_TREMOVE = 122,
|
|
|
|
P9_RREMOVE,
|
|
|
|
P9_TSTAT = 124,
|
|
|
|
P9_RSTAT,
|
|
|
|
P9_TWSTAT = 126,
|
|
|
|
P9_RWSTAT,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* qid.types */
|
|
|
|
enum {
|
|
|
|
P9_QTDIR = 0x80,
|
|
|
|
P9_QTAPPEND = 0x40,
|
|
|
|
P9_QTEXCL = 0x20,
|
|
|
|
P9_QTMOUNT = 0x10,
|
|
|
|
P9_QTAUTH = 0x08,
|
|
|
|
P9_QTTMP = 0x04,
|
|
|
|
P9_QTSYMLINK = 0x02,
|
|
|
|
P9_QTLINK = 0x01,
|
|
|
|
P9_QTFILE = 0x00,
|
|
|
|
};
|
|
|
|
|
2018-01-08 11:18:22 +01:00
|
|
|
typedef enum P9ProtoVersion {
|
2016-01-07 19:18:02 +01:00
|
|
|
V9FS_PROTO_2000U = 0x01,
|
|
|
|
V9FS_PROTO_2000L = 0x02,
|
2018-01-08 11:18:22 +01:00
|
|
|
} P9ProtoVersion;
|
2016-01-07 19:18:02 +01:00
|
|
|
|
2020-02-08 09:24:19 +01:00
|
|
|
/**
|
|
|
|
* @brief Minimum message size supported by this 9pfs server.
|
|
|
|
*
|
|
|
|
* A client establishes a session by sending a Tversion request along with a
|
|
|
|
* 'msize' parameter which suggests the server a maximum message size ever to be
|
|
|
|
* used for communication (for both requests and replies) between client and
|
|
|
|
* server during that session. If client suggests a 'msize' smaller than this
|
|
|
|
* value then session is denied by server with an error response.
|
|
|
|
*/
|
|
|
|
#define P9_MIN_MSIZE 4096
|
|
|
|
|
2017-01-03 17:28:44 +01:00
|
|
|
#define P9_NOTAG UINT16_MAX
|
|
|
|
#define P9_NOFID UINT32_MAX
|
2016-01-07 19:18:02 +01:00
|
|
|
#define P9_MAXWELEM 16
|
|
|
|
|
|
|
|
#define FID_REFERENCED 0x1
|
|
|
|
#define FID_NON_RECLAIMABLE 0x2
|
|
|
|
static inline char *rpath(FsContext *ctx, const char *path)
|
|
|
|
{
|
|
|
|
return g_strdup_printf("%s/%s", ctx->fs_root, path);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ample room for Twrite/Rread header
|
|
|
|
* size[4] Tread/Twrite tag[2] fid[4] offset[8] count[4]
|
|
|
|
*/
|
|
|
|
#define P9_IOHDRSZ 24
|
|
|
|
|
|
|
|
typedef struct V9fsPDU V9fsPDU;
|
2017-11-06 18:05:35 +01:00
|
|
|
typedef struct V9fsState V9fsState;
|
2018-01-08 11:18:22 +01:00
|
|
|
typedef struct V9fsTransport V9fsTransport;
|
2016-01-07 19:18:02 +01:00
|
|
|
|
2017-03-21 21:51:34 +01:00
|
|
|
typedef struct {
|
|
|
|
uint32_t size_le;
|
|
|
|
uint8_t id;
|
|
|
|
uint16_t tag_le;
|
|
|
|
} QEMU_PACKED P9MsgHeader;
|
2017-06-29 15:11:50 +02:00
|
|
|
/* According to the specification, 9p messages start with a 7-byte header.
|
|
|
|
* Since most of the code uses this header size in literal form, we must be
|
|
|
|
* sure this is indeed the case.
|
|
|
|
*/
|
|
|
|
QEMU_BUILD_BUG_ON(sizeof(P9MsgHeader) != 7);
|
2017-03-21 21:51:34 +01:00
|
|
|
|
2020-10-30 05:35:14 +01:00
|
|
|
struct V9fsPDU {
|
2016-01-07 19:18:02 +01:00
|
|
|
uint32_t size;
|
|
|
|
uint16_t tag;
|
|
|
|
uint8_t id;
|
|
|
|
uint8_t cancelled;
|
|
|
|
CoQueue complete;
|
2017-11-06 18:05:35 +01:00
|
|
|
V9fsState *s;
|
2016-01-07 19:18:02 +01:00
|
|
|
QLIST_ENTRY(V9fsPDU) next;
|
2016-01-11 10:29:37 +01:00
|
|
|
uint32_t idx;
|
2016-01-07 19:18:02 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* FIXME
|
|
|
|
* 1) change user needs to set groups and stuff
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define MAX_REQ 128
|
|
|
|
#define MAX_TAG_LEN 32
|
|
|
|
|
|
|
|
#define BUG_ON(cond) assert(!(cond))
|
|
|
|
|
|
|
|
typedef struct V9fsFidState V9fsFidState;
|
|
|
|
|
|
|
|
enum {
|
|
|
|
P9_FID_NONE = 0,
|
|
|
|
P9_FID_FILE,
|
|
|
|
P9_FID_DIR,
|
|
|
|
P9_FID_XATTR,
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct V9fsConf
|
|
|
|
{
|
|
|
|
/* tag name for the device */
|
|
|
|
char *tag;
|
|
|
|
char *fsdev_id;
|
|
|
|
} V9fsConf;
|
|
|
|
|
2018-06-07 12:17:22 +02:00
|
|
|
/* 9p2000.L xattr flags (matches Linux values) */
|
|
|
|
#define P9_XATTR_CREATE 1
|
|
|
|
#define P9_XATTR_REPLACE 2
|
|
|
|
|
2016-01-07 19:18:02 +01:00
|
|
|
typedef struct V9fsXattr
|
|
|
|
{
|
2016-11-01 12:00:40 +01:00
|
|
|
uint64_t copied_len;
|
|
|
|
uint64_t len;
|
2016-01-07 19:18:02 +01:00
|
|
|
void *value;
|
|
|
|
V9fsString name;
|
|
|
|
int flags;
|
2016-11-01 12:00:40 +01:00
|
|
|
bool xattrwalk_fid;
|
2016-01-07 19:18:02 +01:00
|
|
|
} V9fsXattr;
|
|
|
|
|
2016-06-06 11:52:34 +02:00
|
|
|
typedef struct V9fsDir {
|
|
|
|
DIR *stream;
|
2020-07-29 10:39:12 +02:00
|
|
|
P9ProtoVersion proto_version;
|
|
|
|
/* readdir mutex type used for 9P2000.u protocol variant */
|
|
|
|
CoMutex readdir_mutex_u;
|
|
|
|
/* readdir mutex type used for 9P2000.L protocol variant */
|
|
|
|
QemuMutex readdir_mutex_L;
|
2016-06-06 11:52:34 +02:00
|
|
|
} V9fsDir;
|
|
|
|
|
2016-06-06 11:52:34 +02:00
|
|
|
static inline void v9fs_readdir_lock(V9fsDir *dir)
|
|
|
|
{
|
2020-07-29 10:39:12 +02:00
|
|
|
if (dir->proto_version == V9FS_PROTO_2000U) {
|
|
|
|
qemu_co_mutex_lock(&dir->readdir_mutex_u);
|
|
|
|
} else {
|
|
|
|
qemu_mutex_lock(&dir->readdir_mutex_L);
|
|
|
|
}
|
2016-06-06 11:52:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void v9fs_readdir_unlock(V9fsDir *dir)
|
|
|
|
{
|
2020-07-29 10:39:12 +02:00
|
|
|
if (dir->proto_version == V9FS_PROTO_2000U) {
|
|
|
|
qemu_co_mutex_unlock(&dir->readdir_mutex_u);
|
|
|
|
} else {
|
|
|
|
qemu_mutex_unlock(&dir->readdir_mutex_L);
|
|
|
|
}
|
2016-06-06 11:52:34 +02:00
|
|
|
}
|
|
|
|
|
2020-07-29 10:39:12 +02:00
|
|
|
static inline void v9fs_readdir_init(P9ProtoVersion proto_version, V9fsDir *dir)
|
2016-06-06 11:52:34 +02:00
|
|
|
{
|
2020-07-29 10:39:12 +02:00
|
|
|
dir->proto_version = proto_version;
|
|
|
|
if (proto_version == V9FS_PROTO_2000U) {
|
|
|
|
qemu_co_mutex_init(&dir->readdir_mutex_u);
|
|
|
|
} else {
|
|
|
|
qemu_mutex_init(&dir->readdir_mutex_L);
|
|
|
|
}
|
2016-06-06 11:52:34 +02:00
|
|
|
}
|
|
|
|
|
2020-07-29 10:12:33 +02:00
|
|
|
/**
|
|
|
|
* Type for 9p fs drivers' (a.k.a. 9p backends) result of readdir requests,
|
|
|
|
* which is a chained list of directory entries.
|
|
|
|
*/
|
|
|
|
typedef struct V9fsDirEnt {
|
|
|
|
/* mandatory (must not be NULL) information for all readdir requests */
|
|
|
|
struct dirent *dent;
|
|
|
|
/*
|
|
|
|
* optional (may be NULL): A full stat of each directory entry is just
|
|
|
|
* done if explicitly told to fs driver.
|
|
|
|
*/
|
|
|
|
struct stat *st;
|
|
|
|
/*
|
|
|
|
* instead of an array, directory entries are always returned as
|
|
|
|
* chained list, that's because the amount of entries retrieved by fs
|
|
|
|
* drivers is dependent on the individual entries' name (since response
|
|
|
|
* messages are size limited), so the final amount cannot be estimated
|
|
|
|
* before hand
|
|
|
|
*/
|
|
|
|
struct V9fsDirEnt *next;
|
|
|
|
} V9fsDirEnt;
|
|
|
|
|
2016-01-07 19:18:02 +01:00
|
|
|
/*
|
|
|
|
* Filled by fs driver on open and other
|
|
|
|
* calls.
|
|
|
|
*/
|
|
|
|
union V9fsFidOpenState {
|
|
|
|
int fd;
|
2016-06-06 11:52:34 +02:00
|
|
|
V9fsDir dir;
|
2016-01-07 19:18:02 +01:00
|
|
|
V9fsXattr xattr;
|
|
|
|
/*
|
|
|
|
* private pointer for fs drivers, that
|
|
|
|
* have its own internal representation of
|
|
|
|
* open files.
|
|
|
|
*/
|
|
|
|
void *private;
|
|
|
|
};
|
|
|
|
|
2020-10-30 05:35:14 +01:00
|
|
|
struct V9fsFidState {
|
2016-01-07 19:18:02 +01:00
|
|
|
int fid_type;
|
|
|
|
int32_t fid;
|
|
|
|
V9fsPath path;
|
|
|
|
V9fsFidOpenState fs;
|
|
|
|
V9fsFidOpenState fs_reclaim;
|
|
|
|
int flags;
|
|
|
|
int open_flags;
|
|
|
|
uid_t uid;
|
|
|
|
int ref;
|
2021-01-18 15:22:58 +01:00
|
|
|
bool clunked;
|
2021-01-18 15:22:59 +01:00
|
|
|
QSIMPLEQ_ENTRY(V9fsFidState) next;
|
2021-01-22 15:35:14 +01:00
|
|
|
QSLIST_ENTRY(V9fsFidState) reclaim_next;
|
2016-01-07 19:18:02 +01:00
|
|
|
};
|
|
|
|
|
2019-10-07 17:02:45 +02:00
|
|
|
typedef enum AffixType_t {
|
|
|
|
AffixType_Prefix,
|
|
|
|
AffixType_Suffix, /* A.k.a. postfix. */
|
|
|
|
} AffixType_t;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Unique affix of variable length.
|
|
|
|
*
|
|
|
|
* An affix is (currently) either a suffix or a prefix, which is either
|
|
|
|
* going to be prepended (prefix) or appended (suffix) with some other
|
|
|
|
* number for the goal to generate unique numbers. Accordingly the
|
|
|
|
* suffixes (or prefixes) we generate @b must all have the mathematical
|
|
|
|
* property of being suffix-free (or prefix-free in case of prefixes)
|
|
|
|
* so that no matter what number we concatenate the affix with, that we
|
|
|
|
* always reliably get unique numbers as result after concatenation.
|
|
|
|
*/
|
|
|
|
typedef struct VariLenAffix {
|
|
|
|
AffixType_t type; /* Whether this affix is a suffix or a prefix. */
|
|
|
|
uint64_t value; /* Actual numerical value of this affix. */
|
|
|
|
/*
|
|
|
|
* Lenght of the affix, that is how many (of the lowest) bits of @c value
|
|
|
|
* must be used for appending/prepending this affix to its final resulting,
|
|
|
|
* unique number.
|
|
|
|
*/
|
|
|
|
int bits;
|
|
|
|
} VariLenAffix;
|
|
|
|
|
|
|
|
/* See qid_inode_prefix_hash_bits(). */
|
|
|
|
typedef struct {
|
|
|
|
dev_t dev; /* FS device on host. */
|
|
|
|
/*
|
|
|
|
* How many (high) bits of the original inode number shall be used for
|
|
|
|
* hashing.
|
|
|
|
*/
|
|
|
|
int prefix_bits;
|
|
|
|
} QpdEntry;
|
2019-10-10 11:36:05 +02:00
|
|
|
|
|
|
|
/* QID path prefix entry, see stat_to_qid */
|
|
|
|
typedef struct {
|
|
|
|
dev_t dev;
|
|
|
|
uint16_t ino_prefix;
|
2019-10-07 17:02:45 +02:00
|
|
|
uint32_t qp_affix_index;
|
|
|
|
VariLenAffix qp_affix;
|
2019-10-10 11:36:05 +02:00
|
|
|
} QppEntry;
|
|
|
|
|
2019-10-07 17:02:45 +02:00
|
|
|
/* QID path full entry, as above */
|
|
|
|
typedef struct {
|
|
|
|
dev_t dev;
|
|
|
|
ino_t ino;
|
|
|
|
uint64_t path;
|
|
|
|
} QpfEntry;
|
|
|
|
|
2020-10-30 05:35:14 +01:00
|
|
|
struct V9fsState {
|
2016-01-07 19:18:02 +01:00
|
|
|
QLIST_HEAD(, V9fsPDU) free_list;
|
|
|
|
QLIST_HEAD(, V9fsPDU) active_list;
|
2021-01-18 15:22:59 +01:00
|
|
|
QSIMPLEQ_HEAD(, V9fsFidState) fid_list;
|
2016-01-07 19:18:02 +01:00
|
|
|
FileOperations *ops;
|
|
|
|
FsContext ctx;
|
|
|
|
char *tag;
|
2018-01-08 11:18:22 +01:00
|
|
|
P9ProtoVersion proto_version;
|
2016-01-07 19:18:02 +01:00
|
|
|
int32_t msize;
|
2017-01-03 17:28:44 +01:00
|
|
|
V9fsPDU pdus[MAX_REQ];
|
2018-01-08 11:18:22 +01:00
|
|
|
const V9fsTransport *transport;
|
2016-01-07 19:18:02 +01:00
|
|
|
/*
|
|
|
|
* lock ensuring atomic path update
|
|
|
|
* on rename.
|
|
|
|
*/
|
|
|
|
CoRwlock rename_lock;
|
|
|
|
int32_t root_fid;
|
|
|
|
Error *migration_blocker;
|
|
|
|
V9fsConf fsconf;
|
2016-08-30 17:02:27 +02:00
|
|
|
V9fsQID root_qid;
|
2019-10-10 11:36:05 +02:00
|
|
|
dev_t dev_id;
|
2019-10-07 17:02:45 +02:00
|
|
|
struct qht qpd_table;
|
2019-10-10 11:36:05 +02:00
|
|
|
struct qht qpp_table;
|
2019-10-07 17:02:45 +02:00
|
|
|
struct qht qpf_table;
|
2019-10-07 17:02:45 +02:00
|
|
|
uint64_t qp_ndevices; /* Amount of entries in qpd_table. */
|
|
|
|
uint16_t qp_affix_next;
|
2019-10-07 17:02:45 +02:00
|
|
|
uint64_t qp_fullpath_next;
|
2017-11-06 18:05:35 +01:00
|
|
|
};
|
2016-01-07 19:18:02 +01:00
|
|
|
|
|
|
|
/* 9p2000.L open flags */
|
|
|
|
#define P9_DOTL_RDONLY 00000000
|
|
|
|
#define P9_DOTL_WRONLY 00000001
|
|
|
|
#define P9_DOTL_RDWR 00000002
|
|
|
|
#define P9_DOTL_NOACCESS 00000003
|
|
|
|
#define P9_DOTL_CREATE 00000100
|
|
|
|
#define P9_DOTL_EXCL 00000200
|
|
|
|
#define P9_DOTL_NOCTTY 00000400
|
|
|
|
#define P9_DOTL_TRUNC 00001000
|
|
|
|
#define P9_DOTL_APPEND 00002000
|
|
|
|
#define P9_DOTL_NONBLOCK 00004000
|
|
|
|
#define P9_DOTL_DSYNC 00010000
|
|
|
|
#define P9_DOTL_FASYNC 00020000
|
|
|
|
#define P9_DOTL_DIRECT 00040000
|
|
|
|
#define P9_DOTL_LARGEFILE 00100000
|
|
|
|
#define P9_DOTL_DIRECTORY 00200000
|
|
|
|
#define P9_DOTL_NOFOLLOW 00400000
|
|
|
|
#define P9_DOTL_NOATIME 01000000
|
|
|
|
#define P9_DOTL_CLOEXEC 02000000
|
|
|
|
#define P9_DOTL_SYNC 04000000
|
|
|
|
|
|
|
|
/* 9p2000.L at flags */
|
|
|
|
#define P9_DOTL_AT_REMOVEDIR 0x200
|
|
|
|
|
|
|
|
/* 9P2000.L lock type */
|
|
|
|
#define P9_LOCK_TYPE_RDLCK 0
|
|
|
|
#define P9_LOCK_TYPE_WRLCK 1
|
|
|
|
#define P9_LOCK_TYPE_UNLCK 2
|
|
|
|
|
|
|
|
#define P9_LOCK_SUCCESS 0
|
|
|
|
#define P9_LOCK_BLOCKED 1
|
|
|
|
#define P9_LOCK_ERROR 2
|
|
|
|
#define P9_LOCK_GRACE 3
|
|
|
|
|
|
|
|
#define P9_LOCK_FLAGS_BLOCK 1
|
|
|
|
#define P9_LOCK_FLAGS_RECLAIM 2
|
|
|
|
|
|
|
|
typedef struct V9fsFlock
|
|
|
|
{
|
|
|
|
uint8_t type;
|
|
|
|
uint32_t flags;
|
|
|
|
uint64_t start; /* absolute offset */
|
|
|
|
uint64_t length;
|
|
|
|
uint32_t proc_id;
|
|
|
|
V9fsString client_id;
|
|
|
|
} V9fsFlock;
|
|
|
|
|
|
|
|
typedef struct V9fsGetlock
|
|
|
|
{
|
|
|
|
uint8_t type;
|
|
|
|
uint64_t start; /* absolute offset */
|
|
|
|
uint64_t length;
|
|
|
|
uint32_t proc_id;
|
|
|
|
V9fsString client_id;
|
|
|
|
} V9fsGetlock;
|
|
|
|
|
|
|
|
extern int open_fd_hw;
|
|
|
|
extern int total_open_fd;
|
|
|
|
|
|
|
|
static inline void v9fs_path_write_lock(V9fsState *s)
|
|
|
|
{
|
|
|
|
if (s->ctx.export_flags & V9FS_PATHNAME_FSCONTEXT) {
|
|
|
|
qemu_co_rwlock_wrlock(&s->rename_lock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void v9fs_path_read_lock(V9fsState *s)
|
|
|
|
{
|
|
|
|
if (s->ctx.export_flags & V9FS_PATHNAME_FSCONTEXT) {
|
|
|
|
qemu_co_rwlock_rdlock(&s->rename_lock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void v9fs_path_unlock(V9fsState *s)
|
|
|
|
{
|
|
|
|
if (s->ctx.export_flags & V9FS_PATHNAME_FSCONTEXT) {
|
|
|
|
qemu_co_rwlock_unlock(&s->rename_lock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint8_t v9fs_request_cancelled(V9fsPDU *pdu)
|
|
|
|
{
|
|
|
|
return pdu->cancelled;
|
|
|
|
}
|
|
|
|
|
2016-10-17 14:13:58 +02:00
|
|
|
void coroutine_fn v9fs_reclaim_fd(V9fsPDU *pdu);
|
2016-10-17 14:13:58 +02:00
|
|
|
void v9fs_path_init(V9fsPath *path);
|
|
|
|
void v9fs_path_free(V9fsPath *path);
|
|
|
|
void v9fs_path_sprintf(V9fsPath *path, const char *fmt, ...);
|
2018-02-19 18:27:15 +01:00
|
|
|
void v9fs_path_copy(V9fsPath *dst, const V9fsPath *src);
|
2020-07-29 10:11:15 +02:00
|
|
|
size_t v9fs_readdir_response_size(V9fsString *name);
|
2016-10-17 14:13:58 +02:00
|
|
|
int v9fs_name_to_path(V9fsState *s, V9fsPath *dirpath,
|
|
|
|
const char *name, V9fsPath *path);
|
2018-02-01 21:21:27 +01:00
|
|
|
int v9fs_device_realize_common(V9fsState *s, const V9fsTransport *t,
|
|
|
|
Error **errp);
|
qdev: Unrealize must not fail
Devices may have component devices and buses.
Device realization may fail. Realization is recursive: a device's
realize() method realizes its components, and device_set_realized()
realizes its buses (which should in turn realize the devices on that
bus, except bus_set_realized() doesn't implement that, yet).
When realization of a component or bus fails, we need to roll back:
unrealize everything we realized so far. If any of these unrealizes
failed, the device would be left in an inconsistent state. Must not
happen.
device_set_realized() lets it happen: it ignores errors in the roll
back code starting at label child_realize_fail.
Since realization is recursive, unrealization must be recursive, too.
But how could a partly failed unrealize be rolled back? We'd have to
re-realize, which can fail. This design is fundamentally broken.
device_set_realized() does not roll back at all. Instead, it keeps
unrealizing, ignoring further errors.
It can screw up even for a device with no buses: if the lone
dc->unrealize() fails, it still unregisters vmstate, and calls
listeners' unrealize() callback.
bus_set_realized() does not roll back either. Instead, it stops
unrealizing.
Fortunately, no unrealize method can fail, as we'll see below.
To fix the design error, drop parameter @errp from all the unrealize
methods.
Any unrealize method that uses @errp now needs an update. This leads
us to unrealize() methods that can fail. Merely passing it to another
unrealize method cannot cause failure, though. Here are the ones that
do other things with @errp:
* virtio_serial_device_unrealize()
Fails when qbus_set_hotplug_handler() fails, but still does all the
other work. On failure, the device would stay realized with its
resources completely gone. Oops. Can't happen, because
qbus_set_hotplug_handler() can't actually fail here. Pass
&error_abort to qbus_set_hotplug_handler() instead.
* hw/ppc/spapr_drc.c's unrealize()
Fails when object_property_del() fails, but all the other work is
already done. On failure, the device would stay realized with its
vmstate registration gone. Oops. Can't happen, because
object_property_del() can't actually fail here. Pass &error_abort
to object_property_del() instead.
* spapr_phb_unrealize()
Fails and bails out when remove_drcs() fails, but other work is
already done. On failure, the device would stay realized with some
of its resources gone. Oops. remove_drcs() fails only when
chassis_from_bus()'s object_property_get_uint() fails, and it can't
here. Pass &error_abort to remove_drcs() instead.
Therefore, no unrealize method can fail before this patch.
device_set_realized()'s recursive unrealization via bus uses
object_property_set_bool(). Can't drop @errp there, so pass
&error_abort.
We similarly unrealize with object_property_set_bool() elsewhere,
always ignoring errors. Pass &error_abort instead.
Several unrealize methods no longer handle errors from other unrealize
methods: virtio_9p_device_unrealize(),
virtio_input_device_unrealize(), scsi_qdev_unrealize(), ...
Much of the deleted error handling looks wrong anyway.
One unrealize methods no longer ignore such errors:
usb_ehci_pci_exit().
Several realize methods no longer ignore errors when rolling back:
v9fs_device_realize_common(), pci_qdev_unrealize(),
spapr_phb_realize(), usb_qdev_realize(), vfio_ccw_realize(),
virtio_device_realize().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200505152926.18877-17-armbru@redhat.com>
2020-05-05 17:29:24 +02:00
|
|
|
void v9fs_device_unrealize_common(V9fsState *s);
|
2016-01-07 19:18:02 +01:00
|
|
|
|
2016-01-07 19:35:12 +01:00
|
|
|
V9fsPDU *pdu_alloc(V9fsState *s);
|
|
|
|
void pdu_free(V9fsPDU *pdu);
|
2017-05-25 10:30:13 +02:00
|
|
|
void pdu_submit(V9fsPDU *pdu, P9MsgHeader *hdr);
|
2016-10-17 14:13:58 +02:00
|
|
|
void v9fs_reset(V9fsState *s);
|
2016-01-07 19:18:02 +01:00
|
|
|
|
2017-01-03 17:28:44 +01:00
|
|
|
struct V9fsTransport {
|
|
|
|
ssize_t (*pdu_vmarshal)(V9fsPDU *pdu, size_t offset, const char *fmt,
|
|
|
|
va_list ap);
|
|
|
|
ssize_t (*pdu_vunmarshal)(V9fsPDU *pdu, size_t offset, const char *fmt,
|
|
|
|
va_list ap);
|
2017-01-03 17:28:44 +01:00
|
|
|
void (*init_in_iov_from_pdu)(V9fsPDU *pdu, struct iovec **piov,
|
2020-05-21 21:26:25 +02:00
|
|
|
unsigned int *pniov, size_t size);
|
2017-01-03 17:28:44 +01:00
|
|
|
void (*init_out_iov_from_pdu)(V9fsPDU *pdu, struct iovec **piov,
|
2017-06-29 15:11:51 +02:00
|
|
|
unsigned int *pniov, size_t size);
|
2017-01-03 17:28:44 +01:00
|
|
|
void (*push_and_notify)(V9fsPDU *pdu);
|
|
|
|
};
|
|
|
|
|
2016-01-07 19:18:02 +01:00
|
|
|
#endif
|