1. 01 4月, 2009 1 次提交
    • J
      loop: add ioctl to resize a loop device · 53d66608
      J. R. Okajima 提交于
      Add the ability to 'resize' the loop device on the fly.
      
      One practical application is a loop file with XFS filesystem, already
      mounted: You can easily enlarge the file (append some bytes) and then call
      ioctl(fd, LOOP_SET_CAPACITY, new); The loop driver will learn about the
      new size and you can use xfs_growfs later on, which will allow you to use
      full capacity of the loop file without the need to unmount.
      
      Test app:
      
      #include <linux/fs.h>
      #include <linux/loop.h>
      #include <sys/ioctl.h>
      #include <sys/stat.h>
      #include <sys/types.h>
      #include <assert.h>
      #include <errno.h>
      #include <fcntl.h>
      #include <stdio.h>
      #include <stdlib.h>
      #include <unistd.h>
      
      #define _GNU_SOURCE
      #include <getopt.h>
      
      char *me;
      
      void usage(FILE *f)
      {
      	fprintf(f, "%s [options] loop_dev [backend_file]\n"
      		"-s, --set new_size_in_bytes\n"
      		"\twhen backend_file is given, "
      		"it will be expanded too while keeping the original contents\n",
      		me);
      }
      
      struct option opts[] = {
      	{
      		.name		= "set",
      		.has_arg	= 1,
      		.flag		= NULL,
      		.val		= 's'
      	},
      	{
      		.name		= "help",
      		.has_arg	= 0,
      		.flag		= NULL,
      		.val		= 'h'
      	}
      };
      
      void err_size(char *name, __u64 old)
      {
      	fprintf(stderr, "size must be larger than current %s (%llu)\n",
      		name, old);
      }
      
      int main(int argc, char *argv[])
      {
      	int fd, err, c, i, bfd;
      	ssize_t ssz;
      	size_t sz;
      	__u64 old, new, append;
      	char a[BUFSIZ];
      	struct stat st;
      	FILE *out;
      	char *backend, *dev;
      
      	err = EINVAL;
      	out = stderr;
      	me = argv[0];
      	new = 0;
      	while ((c = getopt_long(argc, argv, "s:h", opts, &i)) != -1) {
      		switch (c) {
      		case 's':
      			errno = 0;
      			new = strtoull(optarg, NULL, 0);
      			if (errno) {
      				err = errno;
      				perror(argv[i]);
      				goto out;
      			}
      			break;
      
      		case 'h':
      			err = 0;
      			out = stdout;
      			goto err;
      
      		default:
      			perror(argv[i]);
      			goto err;
      		}
      	}
      
      	if (optind < argc)
      		dev = argv[optind++];
      	else
      		goto err;
      
      	fd = open(dev, O_RDONLY);
      	if (fd < 0) {
      		err = errno;
      		perror(dev);
      		goto out;
      	}
      
      	err = ioctl(fd, BLKGETSIZE64, &old);
      	if (err) {
      		err = errno;
      		perror("ioctl BLKGETSIZE64");
      		goto out;
      	}
      
      	if (!new) {
      		printf("%llu\n", old);
      		goto out;
      	}
      
      	if (new < old) {
      		err = EINVAL;
      		err_size(dev, old);
      		goto out;
      	}
      
      	if (optind < argc) {
      		backend = argv[optind++];
      		bfd = open(backend, O_WRONLY|O_APPEND);
      		if (bfd < 0) {
      			err = errno;
      			perror(backend);
      			goto out;
      		}
      		err = fstat(bfd, &st);
      		if (err) {
      			err = errno;
      			perror(backend);
      			goto out;
      		}
      		if (new < st.st_size) {
      			err = EINVAL;
      			err_size(backend, st.st_size);
      			goto out;
      		}
      		append = new - st.st_size;
      		sz = sizeof(a);
      		while (append > 0) {
      			if (append < sz)
      				sz = append;
      			ssz = write(bfd, a, sz);
      			if (ssz != sz) {
      				err = errno;
      				perror(backend);
      				goto out;
      			}
      			append -= sz;
      		}
      		err = fsync(bfd);
      		if (err) {
      			err = errno;
      			perror(backend);
      			goto out;
      		}
      	}
      
      	err = ioctl(fd, LOOP_SET_CAPACITY, new);
      	if (err) {
      		err = errno;
      		perror("ioctl LOOP_SET_CAPACITY");
      	}
      	goto out;
      
       err:
      	usage(out);
       out:
      	return err;
      }
      Signed-off-by: NJ. R. Okajima <hooanon05@yahoo.co.jp>
      Signed-off-by: NTomas Matejicek <tomas@slax.org>
      Cc: <util-linux-ng@vger.kernel.org>
      Cc: Karel Zak <kzak@redhat.com>
      Cc: Jens Axboe <jens.axboe@oracle.com>
      Cc: Al Viro <viro@zeniv.linux.org.uk>
      Cc: Christoph Hellwig <hch@lst.de>
      Cc: Akinobu Mita <akinobu.mita@gmail.com>
      Cc: <linux-api@vger.kernel.org>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      53d66608
  2. 16 1月, 2009 1 次提交
  3. 07 2月, 2008 1 次提交
    • D
      Allow auto-destruction of loop devices · 96c58655
      David Woodhouse 提交于
      This allows a flag to be set on loop devices so that when they are
      closed for the last time, they'll self-destruct.
      
      In general, so that we can automatically allocate loop devices (as with
      losetup -f) and have them disappear when we're done with them.
      
      In particular, right now, so that we can stop relying on the hackish
      special-case in umount(8) which kills off loop devices which were set up by
      'mount -oloop'.  That means we can stop putting crap in /etc/mtab which
      doesn't belong there, which means it can be a symlink to /proc/mounts, which
      means yet another writable file on the root filesystem is eliminated and the
      'stateless' folks get happier...  and OLPC trac #356 can be closed.
      
      The mount(8) side of that is at
      http://marc.info/?l=util-linux-ng&m=119362955431694&w=2
      
      [akpm@linux-foundation.org: coding-style fixes]
      Signed-off-by: NDavid Woodhouse <dwmw2@infradead.org>
      Cc: Bernardo Innocenti <bernie@codewiz.org>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      96c58655
  4. 25 7月, 2007 1 次提交
  5. 24 7月, 2007 1 次提交
  6. 09 5月, 2007 1 次提交
    • K
      remove artificial software max_loop limit · 73285082
      Ken Chen 提交于
      Remove artificial maximum 256 loop device that can be created due to a
      legacy device number limit.  Searching through lkml archive, there are
      several instances where users complained about the artificial limit that
      the loop driver impose.  There is no reason to have such limit.
      
      This patch rid the limit entirely and make loop device and associated block
      queue instantiation on demand.  With on-demand instantiation, it also gives
      the benefit of not wasting memory if these devices are not in use (compare
      to current implementation that always create 8 loop devices), a net
      improvement in both areas.  This version is both tested with creation of
      large number of loop devices and is compatible with existing losetup/mount
      user land tools.
      
      There are a number of people who worked on this and provided valuable
      suggestions, in no particular order, by:
      
      Jens Axboe
      Jan Engelhardt
      Christoph Hellwig
      Thomas M
      Signed-off-by: NKen Chen <kenchen@google.com>
      Cc: Jan Engelhardt <jengelh@linux01.gwdg.de>
      Cc: Christoph Hellwig <hch@lst.de>
      Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      73285082
  7. 30 9月, 2006 1 次提交
  8. 27 6月, 2006 1 次提交
    • L
      Revert "[PATCH] kthread: update loop.c to use kthread" · 09c0dc68
      Linus Torvalds 提交于
      This reverts commit c7b2eff0.
      
      Hugh Dickins explains:
      
       "It seems too little tested: "losetup -d /dev/loop0" fails with
        EINVAL because nothing sets lo_thread; but even when you patch
        loop_thread() to set lo->lo_thread = current, it can't survive
        more than a few dozen iterations of the loop below (with a tmpfs
        mounted on /tst):
      
      	j=0
      	cp /dev/zero /tst
      	while :
      	do
      	    let j=j+1
      	    echo "Doing pass $j"
      	    losetup /dev/loop0 /tst/zero
      	    mkfs -t ext2 -b 1024 /dev/loop0 >/dev/null 2>&1
      	    mount -t ext2 /dev/loop0 /mnt
      	    umount /mnt
      	    losetup -d /dev/loop0
      	done
      
        it collapses with failed ioctl then BUG_ON(!bio).
      
        I think the original lo_done completion was more subtle and safe
        than the kthread conversion has allowed for."
      Signed-off-by: NLinus Torvalds <torvalds@osdl.org>
      09c0dc68
  9. 26 6月, 2006 1 次提交
  10. 23 3月, 2006 1 次提交
  11. 10 1月, 2006 1 次提交
  12. 28 10月, 2005 1 次提交
  13. 24 6月, 2005 1 次提交
    • N
      [PATCH] optimise loop driver a bit · 35a82d1a
      Nick Piggin 提交于
      Looks like locking can be optimised quite a lot.  Increase lock widths
      slightly so lo_lock is taken fewer times per request.  Also it was quite
      trivial to cover lo_pending with that lock, and remove the atomic
      requirement.  This also makes memory ordering explicitly correct, which is
      nice (not that I particularly saw any mem ordering bugs).
      
      Test was reading 4 250MB files in parallel on ext2-on-tmpfs filesystem (1K
      block size, 4K page size).  System is 2 socket Xeon with HT (4 thread).
      
      intel:/home/npiggin# umount /dev/loop0 ; mount /dev/loop0 /mnt/loop ; /usr/bin/time ./mtloop.sh
      
      Before:
      0.24user 5.51system 0:02.84elapsed 202%CPU (0avgtext+0avgdata 0maxresident)k
      0.19user 5.52system 0:02.88elapsed 198%CPU (0avgtext+0avgdata 0maxresident)k
      0.19user 5.57system 0:02.89elapsed 198%CPU (0avgtext+0avgdata 0maxresident)k
      0.22user 5.51system 0:02.90elapsed 197%CPU (0avgtext+0avgdata 0maxresident)k
      0.19user 5.44system 0:02.91elapsed 193%CPU (0avgtext+0avgdata 0maxresident)k
      
      After:
      0.07user 2.34system 0:01.68elapsed 143%CPU (0avgtext+0avgdata 0maxresident)k
      0.06user 2.37system 0:01.68elapsed 144%CPU (0avgtext+0avgdata 0maxresident)k
      0.06user 2.39system 0:01.68elapsed 145%CPU (0avgtext+0avgdata 0maxresident)k
      0.06user 2.36system 0:01.68elapsed 144%CPU (0avgtext+0avgdata 0maxresident)k
      0.06user 2.42system 0:01.68elapsed 147%CPU (0avgtext+0avgdata 0maxresident)k
      Signed-off-by: NNick Piggin <nickpiggin@yahoo.com.au>
      Signed-off-by: NAndrew Morton <akpm@osdl.org>
      Signed-off-by: NLinus Torvalds <torvalds@osdl.org>
      35a82d1a
  14. 17 4月, 2005 1 次提交
    • L
      Linux-2.6.12-rc2 · 1da177e4
      Linus Torvalds 提交于
      Initial git repository build. I'm not bothering with the full history,
      even though we have it. We can create a separate "historical" git
      archive of that later if we want to, and in the meantime it's about
      3.2GB when imported into git - space that would just make the early
      git days unnecessarily complicated, when we don't have a lot of good
      infrastructure for it.
      
      Let it rip!
      1da177e4