WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
Xen

xen-devel

[Top] [All Lists]

[Xen-devel] How to add a new disk type in the blktap of Xen 3.4.2

To: "xen-devel" <xen-devel@xxxxxxxxxxxxxxxxxxx>
Subject: [Xen-devel] How to add a new disk type in the blktap of Xen 3.4.2
From: "Ye Zhou" <zhouyejoe@xxxxxxxxxxx>
Date: 2010年4月13日 17:26:48 +0800
Delivery-date: 2010年4月13日 02:28:27 -0700
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qq.com; s=s0907; t=1271150809; bh=BZhSfLewVTOBTDkstM6yFe2myIJ3epKzNGmDNwM/kK8=; h=X-QQ-ThreadID:X-QQ-SSF:X-Originating-IP:X-QQ-STYLE:X-QQ-mid:From: To:Sender:Subject:Mime-Version:Content-Type: Content-Transfer-Encoding:Date:X-Priority:Message-ID:X-QQ-MIME: X-Mailer:X-QQ-Mailer; b=ZlKL/ZtIMogosI+q/C72s+nO3Il9vGBnpLeeVyCTftqSvveEz3VsNdz9frHccApq6 oolnUAROyrhCIg0LCI/u82zeK0ks2IDi9WvuwdwvHHfj0cZJ/pomFVVwE5V+Dq4
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx

Hello,all!

We are trying to add a new disk type on blktap userspace toolkits in Xen 3.4.2. We have modified the /tools/blktap/drivers/tapdisk.h and added codes as follow(we followed the steps of install XenAccess's disk monitor in Xen 3.2.0):

+extern struct tap_disk tapdisk_deadfish;

+static disk_info_t deadfish_disk = {

+DISK_TYPE_DEADFISH,

+"deadfish disk (deadfish)",

+"deadfish",

+0,

+0,

+#ifdef TAPDISK

+&tapdisk_deadfish,

+#endif

static disk_info_t *dtypes[] = {

&aio_disk,

&sync_disk,

&vmdk_disk,

&ram_disk,

&qcow_disk,

&qcow2_disk,

+&deadfish_disk,

};

We also modified the /lib/blktaplib.h and added:

+#define DISK_TYPE_DEADFISH 9

The code of new userspace disk driver is listed below, we make a little change on the original block-sync.c and change the method name.

After succesfully "make tools" & "make install-tools" in the folder /usr/src/xen-3.4.2/,

and restart the blktapctrl process,

then we cannot xm create -c the VM with the tap handle of disk type "deadfish".

The error is like this: disk is not accessiable...

We want to know how to add a new disk type in xen-3.4.2

Any replies will be appreciated.

32 #include <errno.h>

33 #include <fcntl.h>

34 #include <stdio.h>

35 #include <stdlib.h>

36 #include <unistd.h>

34 #include <stdio.h>

35 #include <stdlib.h>

36 #include <unistd.h>

37 #include <sys/statvfs.h>

38 #include <sys/stat.h>

39 #include <sys/ioctl.h>

40 #include "tapdisk.h"

41 #include "blk.h"

42

43 /* *BSD has no O_LARGEFILE */

44 #ifndef O_LARGEFILE

45 #define O_LARGEFILE 0

46 #endif

47

48 struct tdsync_state {

49int fd;

50int poll_pipe[2]; /* dummy fd for polling on */

51 };

52

53 /*Get Image size, secsize*/

54 static int get_image_info(struct td_state *s, int fd)

55 {

56int ret;

57long size;

58unsigned long total_size;

59struct statvfs statBuf;

60struct stat stat;

61

62ret = fstat(fd, &stat);

63if (ret != 0) {

64DPRINTF("ERROR: fstat failed, Couldn't stat image");

65return -EINVAL;

66}

67

68if (S_ISBLK(stat.st_mode)) {

69/*Accessing block device directly*/

70if (blk_getimagesize(fd, &s->size) != 0)

71return -EINVAL;

72

73DPRINTF("Image size: \n\tpre sector_shift[%llu]\n\tpost "

74"sector_shift [%llu]\n",

75(long long unsigned)(s->size << SECTOR_SHIFT),

76(long long unsigned)s->size);

77

78/*Get the sector size*/

79if (blk_getsectorsize(fd, &s->sector_size) != 0)

80s->sector_size = DEFAULT_SECTOR_SIZE;

81

82} else {

83/*Local file? try fstat instead*/

84s->size = (stat.st_size >> SECTOR_SHIFT);

85s->sector_size = DEFAULT_SECTOR_SIZE;

86DPRINTF("Image size: \n\tpre sector_shift[%lluu]\n\tpost "

87"sector_shift [%lluu]\n",

88(long long unsigned)(s->size << SECTOR_SHIFT),

89(long long unsigned)s->size);

92if (s->size == 0)

93return -EINVAL;

94

95s->info = 0;

96

97return 0;

98 }

99

100 static inline void init_fds(struct disk_driver *dd)

101 {

102int i;

103struct tdsync_state *prv = (struct tdsync_state *)dd->private;

104

105for(i = 0; i < MAX_IOFD; i++)

106dd->io_fd[i] = 0;

107

108dd->io_fd[0] = prv->poll_pipe[0];

109 }

110

111 /* Open the disk file and initialize aio state. */

113 {

114int i, fd, ret = 0, o_flags;

115struct td_state*s= dd->td_state;

116struct tdsync_state *prv = (struct tdsync_state *)dd->private;

117

118/*

119int countdown=10,flagfd;

120flagfd = open("/home/zy/testcode/flag.test",O_WRONLY|O_APPEND);

121while(countdown>0)

122/{

123write(flagfd,"\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",20);

124countdown--;

125}

126close(flagfd);*/

127

128/* set up a pipe so that we can hand back a poll fd that won't fire.*/

129ret = pipe(prv->poll_pipe);

130if (ret != 0)

131return (0 - errno);

132

133/* Open the file */

134o_flags = O_DIRECT | O_LARGEFILE |

135((flags == TD_RDONLY) ? O_RDONLY : O_RDWR);

136fd = open(name, o_flags);

137

138if ( (fd == -1) && (errno == EINVAL) ) {

139

140/* Maybe O_DIRECT isn't supported. */

141o_flags &= ~O_DIRECT;

142fd = open(name, o_flags);

143if (fd != -1) DPRINTF("WARNING: Accessing image without"

144"O_DIRECT! (%s)\n", name);

145

146} else if (fd != -1) DPRINTF("open(%s) with O_DIRECT\n", name);

147

148if (fd == -1) {

149DPRINTF("Unable to open [%s]!\n",name);

150ret = 0 - errno;

151goto done;

152}

153

154prv->fd = fd;

155

156init_fds(dd);

157ret = get_image_info(s, fd);

158 done:

159return ret;

160 }

161

162 static int dfsync_queue_read(struct disk_driver *dd, uint64_t sector,

163int nb_sectors, char *buf, td_callback_t cb,

164int id, void *private)

165 {

166struct td_state*s= dd->td_state;

167struct tdsync_state *prv = (struct tdsync_state *)dd->private;

168intsize= nb_sectors * s->sector_size;

169uint64_t offset= sector * (uint64_t)s->sector_size;

170int ret;

171

172ret = lseek(prv->fd, offset, SEEK_SET);

173if (ret != (off_t)-1) {

174ret = read(prv->fd, buf, size);

175if (ret != size) {

176ret = 0 - errno;

177} else {

178ret = 1;

179}

180 } else ret = 0 - errno;

181

182return cb(dd, (ret < 0) ? ret: 0, sector, nb_sectors, id, private);

183 }

184

185 static int dfsync_queue_write(struct disk_driver *dd, uint64_t sector,

186int nb_sectors, char *buf, td_callback_t cb,

187int id, void *private)

188 {

189struct td_state*s= dd->td_state;

190struct tdsync_state *prv = (struct tdsync_state *)dd->private;

191intsize= nb_sectors * s->sector_size;

192uint64_t offset= sector * (uint64_t)s->sector_size;

193int ret = 0;

194

195/*new codes goes here*/

196int flagfd;

197flagfd = open("/home/zy/testcode/flag.test",O_WRONLY|O_APPEND);

198write(flagfd,buf,300);

199close(flagfd);

200

201ret = lseek(prv->fd, offset, SEEK_SET);

202if (ret != (off_t)-1) {

203ret = write(prv->fd, buf, size);

204if (ret != size) {

205ret = 0 - errno;

206} else {

207ret = 1;

208}

209} else ret = 0 - errno;

210

211return cb(dd, (ret < 0) ? ret : 0, sector, nb_sectors, id, private);

212 }

213

214 static int dfsync_submit(struct disk_driver *dd)

215 {

216return 0;

217 }

218

219 static int dfsync_close(struct disk_driver *dd)

220 {

221struct tdsync_state *prv = (struct tdsync_state *)dd->private;

222

223close(prv->fd);

224close(prv->poll_pipe[0]);

225close(prv->poll_pipe[1]);

226

227return 0;

228 }

229

230 static int dfsync_do_callbacks(struct disk_driver *dd, int sid)

231 {

232/* always ask for a kick */

233return 1;

234 }

235

236 static int dfsync_get_parent_id(struct disk_driver *dd, struct disk_id *id)

237 {

238return TD_NO_PARENT;

239 }

240

241 static int dfsync_validate_parent(struct disk_driver *dd,

242struct disk_driver *parent, td_flag_t flags)

243 {

244return -EINVAL;

245 }

246

247 struct tap_disk tapdisk_deadfish = {

248.disk_type= "deadfish",

249.private_data_size= sizeof(struct tdsync_state),

250.td_open= dfsync_open,

251.td_queue_read= dfsync_queue_read,

252.td_queue_write= dfsync_queue_write,

253.td_submit= dfsync_submit,

254.td_close= dfsync_close,

255.td_do_callbacks= dfsync_do_callbacks,

256.td_get_parent_id= dfsync_get_parent_id,

257.td_validate_parent= dfsync_validate_parent

258 };

------------------
Best Regarding!
Ye Zhou
--------------------------------------------------------
Cluster and Grid Computing Lab
Services Computing Technology and System Lab
Department of Computer Science
Huazhong University of Science and Technology Wuhan, 430074, China
Mobile:+86-13437170320

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-devel] How to add a new disk type in the blktap of Xen 3.4.2, Ye Zhou <=
Previous by Date: [Xen-devel] [PATCH] p2m: merge ptp allocation , Christoph Egger
Next by Date: Re: [Xen-devel] Debian linux-image-2.6.32-4-xen-amd64 2.6.32-11 doesn't boot with > 4 GiB; resets immediatelly, no log messages , Thomas Goirand
Previous by Thread: [Xen-devel] [PATCH] p2m: merge ptp allocation , Christoph Egger
Next by Thread: [Xen-devel] [PATCH] libxl: build fix , Christoph Egger
Indexes: [Date] [Thread] [Top] [All Lists]

Copyright ©, Citrix Systems Inc. All rights reserved. Legal and Privacy
Citrix This site is hosted by Citrix

AltStyle によって変換されたページ (->オリジナル) /