|
230 |
file=$(readlink -f "$p") || fatal "$p does not exist." |
230 |
file=$(readlink -f "$p") || fatal "$p does not exist." |
231 |
test -f "$file" || fatal "$file does not exist." |
231 |
test -f "$file" || fatal "$file does not exist." |
232 |
mode=$(canonicalise_mode "$mode") |
232 |
mode=$(canonicalise_mode "$mode") |
|
|
233 |
major_minor=$(stat -c [%D]:%i "$file") |
233 |
|
234 |
|
234 |
claim_lock "block" |
235 |
claim_lock "block" |
235 |
|
236 |
|
|
241 |
mount it read-write in a guest domain." |
242 |
mount it read-write in a guest domain." |
242 |
fi |
243 |
fi |
243 |
|
244 |
|
244 |
loopdev='' |
245 |
if [ "x$mode" != 'x!' ] |
245 |
for dev in /dev/loop* |
246 |
then |
246 |
do |
247 |
while IFS=$'\t' read dev lmajor_minor f |
247 |
if [ ! -b "$dev" ] |
248 |
do |
248 |
then |
249 |
if [ "$major_minor" != "$lmajor_minor" ] |
249 |
continue |
|
|
250 |
fi |
251 |
|
252 |
f=$(losetup "$dev" 2>/dev/null) || f='' |
253 |
|
254 |
if [ "$f" ] |
255 |
then |
256 |
# $dev is in use. Check sharing. |
257 |
if [ "x$mode" = 'x!' ] |
258 |
then |
250 |
then |
259 |
continue |
251 |
continue |
260 |
fi |
252 |
fi |
261 |
|
253 |
|
262 |
f=$(echo "$f" | sed -e 's/.*(\(.*\)).*/\1/g') |
|
|
263 |
|
264 |
# $f is the filename, as read from losetup, but the loopback |
254 |
# $f is the filename, as read from losetup, but the loopback |
265 |
# driver truncates filenames at 64 characters, so we need to go |
255 |
# driver truncates filenames at 64 characters, so we need to go |
266 |
# trawling through the store if it's longer than that. Truncation |
256 |
# trawling through the store if it's longer than that. Truncation |
267 |
# is indicated by an asterisk at the end of the filename. |
257 |
# is indicated by an asterisk at the end of the filename. |
268 |
if expr index "$f" '*' >/dev/null |
258 |
if [ "${f:62}" = "*" ] |
269 |
then |
259 |
then |
270 |
found="" |
260 |
found="" |
271 |
for dom in $(xenstore-list "$XENBUS_BASE_PATH") |
261 |
for dom in $(xenstore-list "$XENBUS_BASE_PATH") |
|
318 |
then |
308 |
then |
319 |
check_file_sharing "$file" "$dev" "$mode" |
309 |
check_file_sharing "$file" "$dev" "$mode" |
320 |
fi |
310 |
fi |
321 |
else |
311 |
done < <(losetup -a | sed -e 's,\(/dev/.*\): \(\[[0-9a-f]\+\]:[0-9]\+\) (\(.*\))$,\1\t\2\t\3,') |
322 |
# $dev is not in use, so we'll remember it for use later; we want |
312 |
fi |
323 |
# to finish the sharing check first. |
|
|
324 |
|
325 |
if [ "$loopdev" = '' ] |
326 |
then |
327 |
loopdev="$dev" |
328 |
fi |
329 |
fi |
330 |
done |
331 |
|
313 |
|
332 |
if [ "$loopdev" = '' ] |
314 |
if ! loopdev=$(losetup -f) |
333 |
then |
315 |
then |
334 |
release_lock "block" |
316 |
release_lock "block" |
335 |
fatal 'Failed to find an unused loop device' |
317 |
fatal 'Failed to find an unused loop device' |