Commit a32ef786f4556ebb5e4b7329ac80810ebaa58a81

Authored by aliguori
1 parent ac674887

Introduce new helper function qcow_shedule_bh() (Gleb Natapov)

Use it to remove code duplications from qcow_aio_read_cb().

Signed-off-by: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>



git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5858 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 20 additions and 27 deletions
block-qcow2.c
... ... @@ -1177,6 +1177,20 @@ static void qcow_aio_read_bh(void *opaque)
1177 1177 qcow_aio_read_cb(opaque, 0);
1178 1178 }
1179 1179  
  1180 +static int qcow_schedule_bh(QEMUBHFunc *cb, QCowAIOCB *acb)
  1181 +{
  1182 + if (acb->bh)
  1183 + return -EIO;
  1184 +
  1185 + acb->bh = qemu_bh_new(cb, acb);
  1186 + if (!acb->bh)
  1187 + return -EIO;
  1188 +
  1189 + qemu_bh_schedule(acb->bh);
  1190 +
  1191 + return 0;
  1192 +}
  1193 +
1180 1194 static void qcow_aio_read_cb(void *opaque, int ret)
1181 1195 {
1182 1196 QCowAIOCB *acb = opaque;
... ... @@ -1232,30 +1246,16 @@ fail:
1232 1246 if (acb->hd_aiocb == NULL)
1233 1247 goto fail;
1234 1248 } else {
1235   - if (acb->bh) {
1236   - ret = -EIO;
1237   - goto fail;
1238   - }
1239   - acb->bh = qemu_bh_new(qcow_aio_read_bh, acb);
1240   - if (!acb->bh) {
1241   - ret = -EIO;
  1249 + ret = qcow_schedule_bh(qcow_aio_read_bh, acb);
  1250 + if (ret < 0)
1242 1251 goto fail;
1243   - }
1244   - qemu_bh_schedule(acb->bh);
1245 1252 }
1246 1253 } else {
1247 1254 /* Note: in this case, no need to wait */
1248 1255 memset(acb->buf, 0, 512 * acb->n);
1249   - if (acb->bh) {
1250   - ret = -EIO;
1251   - goto fail;
1252   - }
1253   - acb->bh = qemu_bh_new(qcow_aio_read_bh, acb);
1254   - if (!acb->bh) {
1255   - ret = -EIO;
  1256 + ret = qcow_schedule_bh(qcow_aio_read_bh, acb);
  1257 + if (ret < 0)
1256 1258 goto fail;
1257   - }
1258   - qemu_bh_schedule(acb->bh);
1259 1259 }
1260 1260 } else if (acb->cluster_offset & QCOW_OFLAG_COMPRESSED) {
1261 1261 /* add AIO support for compressed blocks ? */
... ... @@ -1263,16 +1263,9 @@ fail:
1263 1263 goto fail;
1264 1264 memcpy(acb->buf,
1265 1265 s->cluster_cache + index_in_cluster * 512, 512 * acb->n);
1266   - if (acb->bh) {
1267   - ret = -EIO;
1268   - goto fail;
1269   - }
1270   - acb->bh = qemu_bh_new(qcow_aio_read_bh, acb);
1271   - if (!acb->bh) {
1272   - ret = -EIO;
  1266 + ret = qcow_schedule_bh(qcow_aio_read_bh, acb);
  1267 + if (ret < 0)
1273 1268 goto fail;
1274   - }
1275   - qemu_bh_schedule(acb->bh);
1276 1269 } else {
1277 1270 if ((acb->cluster_offset & 511) != 0) {
1278 1271 ret = -EIO;
... ...