qcow2: Fix avail_sectors in cluster allocation code

avail_sectors should really be the number of sectors from the start of
the allocation, not from the start of the write request.

We're lucky enough that this mistake didn't cause any real bug.
avail_sectors is only used in the intialiser of QCowL2Meta:

  .nb_available   = MIN(requested_sectors, avail_sectors),

m->nb_available in turn is only used for COW at the end of the
allocation. A COW occurs only if the request wasn't cluster aligned,
which in turn would imply that requested_sectors was less than
avail_sectors (both in the original and in the fixed version). In this
case avail_sectors is ignored and therefore the mistake doesn't cause
any misbehaviour.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
1 file changed
tree: fe889a84ce2b46db7ab45dd2a2558c863ea64d0e
  1. audio/
  2. block/
  3. bsd-user/
  4. default-configs/
  5. docs/
  6. fpu/
  7. fsdev/
  8. gdb-xml/
  9. hw/
  10. include/
  11. libcacard/
  12. linux-headers/
  13. linux-user/
  14. net/
  15. pc-bios/
  16. qapi/
  17. qga/
  18. QMP/
  19. qom/
  20. roms/
  21. scripts/
  22. slirp/
  23. sysconfigs/
  24. target-alpha/
  25. target-arm/
  26. target-cris/
  27. target-i386/
  28. target-lm32/
  29. target-m68k/
  30. target-microblaze/
  31. target-mips/
  32. target-ppc/
  33. target-s390x/
  34. target-sh4/
  35. target-sparc/
  36. target-unicore32/
  37. target-xtensa/
  38. tcg/
  39. tests/
  40. trace/
  41. ui/
  42. .gitignore
  43. .gitmodules
  44. .mailmap
  45. a.out.h
  46. acl.c
  47. acl.h
  48. aes.c
  49. aes.h
  50. aio.c
  51. alpha-dis.c
  52. alpha.ld
  53. arch_init.c
  54. arch_init.h
  55. arm-dis.c
  56. arm.ld
  57. async.c
  58. balloon.c
  59. balloon.h
  60. bitmap.c
  61. bitmap.h
  62. bitops.c
  63. bitops.h
  64. block-migration.c
  65. block-migration.h
  66. block.c
  67. block.h
  68. block_int.h
  69. blockdev.c
  70. blockdev.h
  71. bswap.h
  72. bt-host.c
  73. bt-host.h
  74. bt-vhci.c
  75. buffered_file.c
  76. buffered_file.h
  77. cache-utils.c
  78. cache-utils.h
  79. Changelog
  80. cmd.c
  81. cmd.h
  82. CODING_STYLE
  83. compatfd.c
  84. compatfd.h
  85. compiler.h
  86. config.h
  87. configure
  88. console.c
  89. console.h
  90. COPYING
  91. COPYING.LIB
  92. coroutine-gthread.c
  93. coroutine-sigaltstack.c
  94. coroutine-ucontext.c
  95. coroutine-win32.c
  96. cpu-all.h
  97. cpu-common.h
  98. cpu-defs.h
  99. cpu-exec.c
  100. cpus.c
  101. cpus.h
  102. cputlb.c
  103. cputlb.h
  104. cris-dis.c
  105. cursor.c
  106. cursor_hidden.xpm
  107. cursor_left_ptr.xpm
  108. cutils.c
  109. def-helper.h
  110. device_tree.c
  111. device_tree.h
  112. dis-asm.h
  113. disas.c
  114. disas.h
  115. dma-helpers.c
  116. dma.h
  117. dump-stub.c
  118. dump.c
  119. dump.h
  120. dyngen-exec.h
  121. elf.h
  122. envlist.c
  123. envlist.h
  124. error.c
  125. error.h
  126. error_int.h
  127. event_notifier.c
  128. event_notifier.h
  129. exec-all.h
  130. exec-memory.h
  131. exec-obsolete.h
  132. exec.c
  133. gdbstub.c
  134. gdbstub.h
  135. gen-icount.h
  136. HACKING
  137. hmp-commands.hx
  138. hmp.c
  139. hmp.h
  140. host-utils.c
  141. host-utils.h
  142. hppa-dis.c
  143. hppa.ld
  144. i386-dis.c
  145. i386.ld
  146. ia64-dis.c
  147. ia64.ld
  148. input.c
  149. int128.h
  150. iohandler.c
  151. ioport.c
  152. ioport.h
  153. iorange.h
  154. iov.c
  155. iov.h
  156. json-lexer.c
  157. json-lexer.h
  158. json-parser.c
  159. json-parser.h
  160. json-streamer.c
  161. json-streamer.h
  162. kvm-all.c
  163. kvm-stub.c
  164. kvm.h
  165. libfdt_env.h
  166. LICENSE
  167. linux-aio.c
  168. lm32-dis.c
  169. m68k-dis.c
  170. m68k.ld
  171. main-loop.c
  172. main-loop.h
  173. MAINTAINERS
  174. Makefile
  175. Makefile.dis
  176. Makefile.hw
  177. Makefile.objs
  178. Makefile.target
  179. Makefile.user
  180. memory.c
  181. memory.h
  182. memory_mapping-stub.c
  183. memory_mapping.c
  184. memory_mapping.h
  185. microblaze-dis.c
  186. migration-exec.c
  187. migration-fd.c
  188. migration-tcp.c
  189. migration-unix.c
  190. migration.c
  191. migration.h
  192. mips-dis.c
  193. mips.ld
  194. module.c
  195. module.h
  196. monitor.c
  197. monitor.h
  198. nbd.c
  199. nbd.h
  200. net.c
  201. net.h
  202. notify.c
  203. notify.h
  204. os-posix.c
  205. os-win32.c
  206. osdep.c
  207. osdep.h
  208. oslib-posix.c
  209. oslib-win32.c
  210. path.c
  211. pci-ids.txt
  212. pflib.c
  213. pflib.h
  214. poison.h
  215. posix-aio-compat.c
  216. ppc-dis.c
  217. ppc.ld
  218. ppc64.ld
  219. qapi-schema-guest.json
  220. qapi-schema-test.json
  221. qapi-schema.json
  222. qbool.c
  223. qbool.h
  224. qdict-test-data.txt
  225. qdict.c
  226. qdict.h
  227. qemu-aio.h
  228. qemu-barrier.h
  229. qemu-bridge-helper.c
  230. qemu-char.c
  231. qemu-char.h
  232. qemu-common.h
  233. qemu-config.c
  234. qemu-config.h
  235. qemu-coroutine-int.h
  236. qemu-coroutine-io.c
  237. qemu-coroutine-lock.c
  238. qemu-coroutine-sleep.c
  239. qemu-coroutine.c
  240. qemu-coroutine.h
  241. qemu-doc.texi
  242. qemu-error.c
  243. qemu-error.h
  244. qemu-file.h
  245. qemu-ga.c
  246. qemu-img-cmds.hx
  247. qemu-img.c
  248. qemu-img.texi
  249. qemu-io.c
  250. qemu-lock.h
  251. qemu-log.h
  252. qemu-nbd.c
  253. qemu-nbd.texi
  254. qemu-objects.h
  255. qemu-option.c
  256. qemu-option.h
  257. qemu-options-wrapper.h
  258. qemu-options.h
  259. qemu-options.hx
  260. qemu-os-posix.h
  261. qemu-os-win32.h
  262. qemu-progress.c
  263. qemu-queue.h
  264. qemu-sockets.c
  265. qemu-tech.texi
  266. qemu-thread-posix.c
  267. qemu-thread-posix.h
  268. qemu-thread-win32.c
  269. qemu-thread-win32.h
  270. qemu-thread.h
  271. qemu-timer-common.c
  272. qemu-timer.c
  273. qemu-timer.h
  274. qemu-tls.h
  275. qemu-tool.c
  276. qemu-user.c
  277. qemu-x509.h
  278. qemu-xattr.h
  279. qemu.sasl
  280. qemu_socket.h
  281. qerror.c
  282. qerror.h
  283. qfloat.c
  284. qfloat.h
  285. qint.c
  286. qint.h
  287. qjson.c
  288. qjson.h
  289. qlist.c
  290. qlist.h
  291. qmp-commands.hx
  292. qmp.c
  293. qobject.h
  294. qstring.c
  295. qstring.h
  296. qtest.c
  297. qtest.h
  298. range.h
  299. readline.c
  300. readline.h
  301. README
  302. rules.mak
  303. s390-dis.c
  304. s390.ld
  305. savevm.c
  306. sh4-dis.c
  307. softmmu-semi.h
  308. softmmu_defs.h
  309. softmmu_exec.h
  310. softmmu_header.h
  311. softmmu_template.h
  312. sparc-dis.c
  313. sparc.ld
  314. sparc64.ld
  315. spice-qemu-char.c
  316. sysemu.h
  317. targphys.h
  318. tcg-runtime.c
  319. tci-dis.c
  320. tci.c
  321. thunk.c
  322. thunk.h
  323. TODO
  324. trace-events
  325. translate-all.c
  326. uboot_image.h
  327. user-exec.c
  328. VERSION
  329. version.rc
  330. vgafont.h
  331. vl.c
  332. vmstate.h
  333. x86_64.ld
  334. xen-all.c
  335. xen-mapcache.c
  336. xen-mapcache.h
  337. xen-stub.c