To follow up on my previous bug report, I found a simple way to make
flashcache_load idempotent with minimal effort and little (or no) risk.
In src/utils/flashcache_load.c, line 179, there is a call to sprintf to
assemble a command line which is then be passed to the subsequent system()
function at line 184. As it is now, it creates a command which
unconditionally issues a dmsetup create command, regardless of whether the
device already exists or not. If it exists already, then this hangs (which
is what I would like to avoid). However, since we are issuing a shell
command already, we can simply prepend a dmsetup status or dmsetup info
command, which will return success if the device already exists and fail if
it does not.
So I substituted the lines
sprintf(echo 0 %lu flashcache %s %s %s %d 1 | dmsetup create %s",
disk_devsize, disk_devname, ssd_devname, cachedev, cache_mode,
cachedev);
with
sprintf(dmsetup_cmd, "dmsetup status %s >/dev/null 2>&1 || echo 0 %lu flashcache %s
%s %s %d 1 | dmsetup create %s",
cachedev, disk_devsize, disk_devname, ssd_devname, cachedev,
cache_mode, cachedev);
The or conditional statement causes the second part of the command (starting
with echo...) to only be executed if the first part (the dmsetup status)
failed. Therefore, if flashcache_load is called on an already loaded device,
it will simply silently ignore it.
This works. Of course, it could be improved easily, e.g. by adding some
additional check on the output of dmsetup status, or by returning a
different error code if the device already exists, or... whatever you want.
As it is now, it is harmless, simple and it works. Use it if you want, or
improve on it, or trash it if you must (then I will have to recompile
flashcache utils everytime with my patch, but ok, my problem...)
Bye
Giacomo
--
_________________________________________________________________
Giacomo Mulas <gmu...@oa-cagliari.inaf.it>
_________________________________________________________________
OSSERVATORIO ASTRONOMICO DI CAGLIARI
Str. 54, Loc. Poggio dei Pini * 09012 Capoterra (CA)
Tel. (OAC): +39 070 71180 248 Fax : +39 070 71180 222
Tel. (UNICA): +39 070 675 4916
_________________________________________________________________
"When the storms are raging around you, stay right where you are"
(Freddy Mercury)
_________________________________________________________________
--
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org