Tmpfs and loop device don't get along

From: Andrew Tipton (andrew@xxxx.xxx)
Date: Fri Feb 01 2002 - 16:19:50 EST


If I have an image (initrd.img for example) located on a tmpfs filesystem,
when I attempt to mount it:

% mount -o loop /initrd.img /mnt
ioctl: LOOP_SET_FD: Invalid argument

After deciding that it was not due to lack of loop devices (/dev/loop0..7),
an unreadable file, and other common userspace causes, I dug through the
kernel sources. When calling LOOP_SET_FD, the single argument is the
filedescriptor of the file (/initrd.img). The loop_set_fd function (in
drivers/block/loop.c) first gets the inode entry for the file, and then the
address_space_operations struct for that inode. If there is no readpage
function in that struct, loop_set_fd fails with EINVAL. The reason for this
check is "if we can't read - sorry" -- apparently testing to see if it's
possible to read from the file/filesystem?

In the tmpfs source (mm/shmem.c), the address_space_operations struct for
this filesystem is defined. The struct (shmem_aops) is defined statically,
and the only member is writepage. readpage is missing, causing a guaranteed
failure in loop_set_fd.

Something smells wrong here (why does loop_set_fd care about
address_space_operations, and not file_operations? it only needs access to
the file....), but I don't know enough about the internal workings of the
page cache/vfs/etc to do much about it.

What is the best way to fix this short-term? I could bypass the readpage
check in loop_set_fd, or I could add a dummy readpage entry to the
address_space_operations struct for tmpfs. Would either of these have
serious repercussions?

I'm not subscribed to the linux-kernel mailing list, so I would appreciate
it if you could CC all replies to me as well.

Thanks,
Andrew Tipton
Cadre5, LLC

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Thu Feb 07 2002 - 21:00:19 EST