1 /* 2 * 9P network client for VirtIO 9P test cases (based on QTest) 3 * 4 * Copyright (c) 2014 SUSE LINUX Products GmbH 5 * 6 * This work is licensed under the terms of the GNU GPL, version 2 or later. 7 * See the COPYING file in the top-level directory. 8 */ 9 10 /* 11 * Not so fast! You might want to read the 9p developer docs first: 12 * https://wiki.qemu.org/Documentation/9p 13 */ 14 15 #ifndef TESTS_LIBQOS_VIRTIO_9P_CLIENT_H 16 #define TESTS_LIBQOS_VIRTIO_9P_CLIENT_H 17 18 #include "hw/9pfs/9p.h" 19 #include "hw/9pfs/9p-synth.h" 20 #include "virtio-9p.h" 21 #include "qgraph.h" 22 #include "tests/qtest/libqtest-single.h" 23 24 #define P9_MAX_SIZE 4096 /* Max size of a T-message or R-message */ 25 26 typedef struct { 27 QTestState *qts; 28 QVirtio9P *v9p; 29 uint16_t tag; 30 uint64_t t_msg; 31 uint32_t t_size; 32 uint64_t r_msg; 33 /* No r_size, it is hardcoded to P9_MAX_SIZE */ 34 size_t t_off; 35 size_t r_off; 36 uint32_t free_head; 37 } P9Req; 38 39 /* type[1] version[4] path[8] */ 40 typedef char v9fs_qid[13]; 41 42 typedef struct v9fs_attr { 43 uint64_t valid; 44 v9fs_qid qid; 45 uint32_t mode; 46 uint32_t uid; 47 uint32_t gid; 48 uint64_t nlink; 49 uint64_t rdev; 50 uint64_t size; 51 uint64_t blksize; 52 uint64_t blocks; 53 uint64_t atime_sec; 54 uint64_t atime_nsec; 55 uint64_t mtime_sec; 56 uint64_t mtime_nsec; 57 uint64_t ctime_sec; 58 uint64_t ctime_nsec; 59 uint64_t btime_sec; 60 uint64_t btime_nsec; 61 uint64_t gen; 62 uint64_t data_version; 63 } v9fs_attr; 64 65 #define P9_GETATTR_BASIC 0x000007ffULL /* Mask for fields up to BLOCKS */ 66 67 struct V9fsDirent { 68 v9fs_qid qid; 69 uint64_t offset; 70 uint8_t type; 71 char *name; 72 struct V9fsDirent *next; 73 }; 74 75 void v9fs_set_allocator(QGuestAllocator *t_alloc); 76 void v9fs_memwrite(P9Req *req, const void *addr, size_t len); 77 void v9fs_memskip(P9Req *req, size_t len); 78 void v9fs_memread(P9Req *req, void *addr, size_t len); 79 void v9fs_uint8_read(P9Req *req, uint8_t *val); 80 void v9fs_uint16_write(P9Req *req, uint16_t val); 81 void v9fs_uint16_read(P9Req *req, uint16_t *val); 82 void v9fs_uint32_write(P9Req *req, uint32_t val); 83 void v9fs_uint64_write(P9Req *req, uint64_t val); 84 void v9fs_uint32_read(P9Req *req, uint32_t *val); 85 void v9fs_uint64_read(P9Req *req, uint64_t *val); 86 uint16_t v9fs_string_size(const char *string); 87 void v9fs_string_write(P9Req *req, const char *string); 88 void v9fs_string_read(P9Req *req, uint16_t *len, char **string); 89 P9Req *v9fs_req_init(QVirtio9P *v9p, uint32_t size, uint8_t id, 90 uint16_t tag); 91 void v9fs_req_send(P9Req *req); 92 void v9fs_req_wait_for_reply(P9Req *req, uint32_t *len); 93 void v9fs_req_recv(P9Req *req, uint8_t id); 94 void v9fs_req_free(P9Req *req); 95 void v9fs_rlerror(P9Req *req, uint32_t *err); 96 P9Req *v9fs_tversion(QVirtio9P *v9p, uint32_t msize, const char *version, 97 uint16_t tag); 98 void v9fs_rversion(P9Req *req, uint16_t *len, char **version); 99 P9Req *v9fs_tattach(QVirtio9P *v9p, uint32_t fid, uint32_t n_uname, 100 uint16_t tag); 101 void v9fs_rattach(P9Req *req, v9fs_qid *qid); 102 P9Req *v9fs_twalk(QVirtio9P *v9p, uint32_t fid, uint32_t newfid, 103 uint16_t nwname, char *const wnames[], uint16_t tag); 104 void v9fs_rwalk(P9Req *req, uint16_t *nwqid, v9fs_qid **wqid); 105 P9Req *v9fs_tgetattr(QVirtio9P *v9p, uint32_t fid, uint64_t request_mask, 106 uint16_t tag); 107 void v9fs_rgetattr(P9Req *req, v9fs_attr *attr); 108 P9Req *v9fs_treaddir(QVirtio9P *v9p, uint32_t fid, uint64_t offset, 109 uint32_t count, uint16_t tag); 110 void v9fs_rreaddir(P9Req *req, uint32_t *count, uint32_t *nentries, 111 struct V9fsDirent **entries); 112 void v9fs_free_dirents(struct V9fsDirent *e); 113 P9Req *v9fs_tlopen(QVirtio9P *v9p, uint32_t fid, uint32_t flags, 114 uint16_t tag); 115 void v9fs_rlopen(P9Req *req, v9fs_qid *qid, uint32_t *iounit); 116 P9Req *v9fs_twrite(QVirtio9P *v9p, uint32_t fid, uint64_t offset, 117 uint32_t count, const void *data, uint16_t tag); 118 void v9fs_rwrite(P9Req *req, uint32_t *count); 119 P9Req *v9fs_tflush(QVirtio9P *v9p, uint16_t oldtag, uint16_t tag); 120 void v9fs_rflush(P9Req *req); 121 P9Req *v9fs_tmkdir(QVirtio9P *v9p, uint32_t dfid, const char *name, 122 uint32_t mode, uint32_t gid, uint16_t tag); 123 void v9fs_rmkdir(P9Req *req, v9fs_qid *qid); 124 P9Req *v9fs_tlcreate(QVirtio9P *v9p, uint32_t fid, const char *name, 125 uint32_t flags, uint32_t mode, uint32_t gid, 126 uint16_t tag); 127 void v9fs_rlcreate(P9Req *req, v9fs_qid *qid, uint32_t *iounit); 128 P9Req *v9fs_tsymlink(QVirtio9P *v9p, uint32_t fid, const char *name, 129 const char *symtgt, uint32_t gid, uint16_t tag); 130 void v9fs_rsymlink(P9Req *req, v9fs_qid *qid); 131 P9Req *v9fs_tlink(QVirtio9P *v9p, uint32_t dfid, uint32_t fid, 132 const char *name, uint16_t tag); 133 void v9fs_rlink(P9Req *req); 134 P9Req *v9fs_tunlinkat(QVirtio9P *v9p, uint32_t dirfd, const char *name, 135 uint32_t flags, uint16_t tag); 136 void v9fs_runlinkat(P9Req *req); 137 138 #endif 139