linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alex Elsayed <eternaleye@gmail.com>
To: linux-btrfs@vger.kernel.org
Subject: Re: lvm volume like support
Date: Wed, 27 Feb 2013 00:50:34 -0800	[thread overview]
Message-ID: <kgkhcp$dfg$1@ger.gmane.org> (raw)
In-Reply-To: 20130227100558.37d86d82@natsu

Roman Mamedov wrote:

> On Wed, 27 Feb 2013 13:23:23 +1100
> "Fajar A. Nugraha" <list@fajar.net> wrote:
> 
>> Not to mention the hassle in accessing the data if it resides on a
>> partition inside the file (e.g. you need losetup + kpartx to access it,
>> and you must remember to do the reverse when you're finished with it).
> 
>> 
>> In zfsonlinux it's very easy to do so since a zvol is treated pretty
>> much like a disk, and whenever there's a partition inside a zvol, a
>> coressponding device noed is also created automatically.
> 
> So I'd say what you (we) need is a generic Linux kernel framework that
> would allow treating any regular file pretty much like a disk. Not some
> filesystem-specific block device emulation kludge.
> 
> Btw some years ago there was a patchset adding proper automatic partition
> support to 'loop'; but it seems like that went nowhere, and I have no idea
> why something this useful did not end up being added into the mainline
> kernel.
> 

I mentioned it in another branch of the thread, but the SCSI Target stack 
*does* this. If you use the FILEIO backend and the 'loopback' transport, you 
get a file that is visible to the local system as Just Another SCSI Disk. 
There are patches on the scsi target list to add UNMAP and WRITE SAME 
w/UNMAP=1 support to the FILEIO backend, at which point it will do 
FL_PUNCH_HOLE operations appropriately.

The commands are:

---cut---

# $IDX = a preferably-unique index
# $NAME = a useful name for humans
# $IMGFILE = a disk image
# $SIZE = the size of $IMGFILE in bytes
# $UUID = a random v4 UUID
# ${NAA[x]} = a valid naa WWN, targetcli generates this as
#     "naa.6001405" + the first 10 digits of a random v4 UUID
#     (not the same uuid as $UUID). When x varies, it's a different
#     WWN, since more than one gets used.

# Load the scsi target core and backends
modprobe target_core_mod

# Tell it where the file is and how big it is
tcm_node --establishdev "fileio_$IDX/$NAME" \
    "fd_dev_name=$IMGFILE,fd_dev_size=$SIZE"

# Give it a unique serial
tcm_node --setunitserialwithmd fileio_$IDX/$NAME $UUID

# Load the local scsi frontend transport
modprobe tcm_loop
mkdir -p /sys/kernel/config/target/loopback

# Some setup so you have a place to put LUNs
mkdir -p /sys/kernel/config/target/loopback/${NAA[1]}/tpgt_1
echo ${NAA[2]} > /sys/kernel/config/target/loopback/${NAA[1]}/tpgt_1/nexus

# Create a fresh LUN...
mkdir -p /sys/kernel/config/target/loopback/${NAA[1]}/tpgt_1/lun/lun_$IDX

# ...and map the file to it.
ln -s /sys/kernel/config/target/core/fileio_$IDX/$NAME \
    /sys/kernel/config/target/loopback/${NAA[1]}/tpgt_1/lun/lun_$IDX

---cut---

This could be pretty easily put into a shell script that uses du -b and 
manually pokes configfs instead of calling tcm_node, and it'd be able to run 
without any nonstandard userspace dependencies.


  parent reply	other threads:[~2013-02-27  8:50 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-25 23:35 lvm volume like support Suman C
2013-02-26  0:59 ` Mike Fleetwood
2013-02-26  1:46   ` Fajar A. Nugraha
2013-02-26  5:35     ` Suman C
2013-02-26  5:48       ` Remco Hosman - Yerf-IT
2013-02-26  5:57       ` Roman Mamedov
2013-02-26  6:25         ` Suman C
2013-02-26  6:28           ` Remco Hosman - Yerf IT
2013-02-26  6:37             ` Alex Elsayed
2013-02-26  7:08             ` Dave Chinner
2013-04-19 18:13           ` Andy Grover
2013-02-26 10:30     ` Martin Steigerwald
2013-02-27  2:23       ` Fajar A. Nugraha
2013-02-27  4:05         ` Roman Mamedov
2013-02-27  8:42           ` Martin Steigerwald
2013-02-27  9:17             ` Roman Mamedov
2013-02-27  8:50           ` Alex Elsayed [this message]
2013-02-27  9:57             ` Alex Elsayed
2013-02-27 10:12               ` Alex Elsayed
2013-04-08 12:01                 ` David Sterba
2013-04-11 12:29                   ` David Sterba
2013-03-02  6:24               ` Marcus Sorensen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='kgkhcp$dfg$1@ger.gmane.org' \
    --to=eternaleye@gmail.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).