Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#3 A patch to add lo_change_fd support

closed
nobody
None
5
2005-06-18
2005-04-18
No

This patch intends to add support for the lo_change_fd
ioctl call, used among other by RedHat based
installation cd's

I have tested it in what I think was success, but would
like some feedback.

mail is
tsukebumi at gmail .com

Discussion

1 2 > >> (Page 1 of 2)
  • Jari Ruusu
    Jari Ruusu
    2005-04-19

    Logged In: YES
    user_id=238645

    I looked at your patch. It is a good start but it
    is far from complete.

    Device backed handling is completely missing. This
    is not a trivial thing to do.

    get_loop_size() is not entirely correct, but is
    easy to fix.

    gpf_mask restoring/setting needs to handle the -1
    case as well as __GFP_HIGH case.

    File backed code uses file->f_op->read()/write()
    so file backed loop_change_fd() code should check
    for ->read() instead of ->sendfile().

    Spanish language comments need to be translated to
    english.

     
  • Logged In: YES
    user_id=392717

    I am just porting a patch that was used some time before.

    The point of it is to be able to switch between two file
    backed loops.

    This is necesary in the installation process since the
    images used in the installation process mounted with a loop
    device, reside on the cd. It is done that way because they
    don't have a proper filesystem where they could move the
    image before mounting it.
    They copy it to one filesystem right after it has been
    created, and to be able to switch cds, they need this ioctl
    command.
    So I think I should return an error if I detect a device
    backed loop? (LOOP_CHANGE_FD is intended for file backed
    loops only, don't know if somebody would find an instance
    where she would need it otherwise)

    I am working on the rest at the time. the comments were
    there just to help me understand how the loop-AES code
    works. I translated the relevant comments to english, and
    removed the rest.

    Thank you very much for your pointers. I really appreciate that.
    This is my first take on some meaningfull community driven,
    not to mention kernel, code.

     
  • revision of the patch. still missing some corrections pointed out by jariruusu

     
  • Jari Ruusu
    Jari Ruusu
    2005-04-20

    Logged In: YES
    user_id=238645

    If this LOOP_CHANGE_FD ioctl can be limited to file
    backed loops only, then your patch can be merged.

    I will merge your second patch version, and fix up the
    remaining loose ends. If I don't encounter any problems
    in testing, then this functionality will be present in
    next version of loop-AES.

    One more thing; Can you post link to Red Hat source
    code that calls this LOOP_CHANGE_FD ioctl? Usage is
    obvious from kernel module source, but I would like to
    see the userspace code that calls it.

    Thanks for your patch porting work.

     
  • Logged In: YES
    user_id=392717

    It is part of <a
    href="http://download.fedora.redhat.com/pub/fedora/linux/core/development/SRPMS/">anaconda</a>.

    It is part python and C.
    The relevant files are isys/isys.py and isys/isys.c, called
    from image.py

    ----isys.py
    def lochangefd(device, file):
    loop = os.open(device, os.O_RDONLY)
    targ = os.open(file, os.O_RDONLY)
    try:
    _isys.lochangefd(loop, targ)
    finally:
    os.close(loop)
    os.close(targ)
    ----isys.c
    static PyObject * doLoChangeFd(PyObject * s, PyObject * args) {
    int loopfd;
    int targfd;

    if (!PyArg_ParseTuple(args, "ii", &loopfd, &targfd))
    return NULL;
    if (ioctl(loopfd, LOOP_CHANGE_FD, targfd)) {
    PyErr_SetFromErrno(PyExc_SystemError);
    return NULL;
    }

    Py_INCREF(Py_None);
    return Py_None;
    }
    ----image.py
    def systemUnmounted(self):
    if self.loopbackFile:
    isys.makeDevInode("loop0", "/tmp/loop")
    isys.lochangefd("/tmp/loop",
    "%s/%s/base/stage2.img" %
    (self.tree, productPath))
    self.loopbackFile = None

    def systemMounted(self, fsset, chroot):
    self.loopbackFile = "%s%s%s" % (chroot,

    fsset.filesystemSpace(chroot)[0][0],
    "/rhinstall-stage2.img")

    try:
    iutil.copyFile("%s/%s/base/stage2.img" %
    (self.tree, productPath),
    self.loopbackFile,
    (self.progressWindow, _("Copying
    File"),
    _("Transferring install image to
    hard drive...")))
    except Exception, e:
    log("error transferring stage2.img: %s" %(e,))
    self.messageWindow(_("Error"),
    _("An error occurred transferring the
    install image "
    "to your hard drive. You are probably
    out of disk "
    "space."))
    os.unlink(self.loopbackFile)
    return 1

    isys.makeDevInode("loop0", "/tmp/loop")
    isys.lochangefd("/tmp/loop", self.loopbackFile)

     
  • Logged In: YES
    user_id=392717

    I just noted this piece of code where change_fd will return
    -EINVAL unless the file is a regular file or a block device

    error = -EINVAL;
    if (!S_ISREG(inode->i_mode) && !S_ISBLK(inode->i_mode)){
    goto out_putf;
    }
    Now I am not sure how this must work.
    Then is the Device backing handling missing? I though it
    should have only checked whether it was regular file only,
    but the original code checks both.

     
  • Jari Ruusu
    Jari Ruusu
    2005-04-21

    Merged version of loop-change-fd patch

     
  • Jari Ruusu
    Jari Ruusu
    2005-04-21

    Logged In: YES
    user_id=238645

    I uploaded new edited version of the patch.

    David, any chance of you testing this?

     
  • Logged In: YES
    user_id=392717

    It worked allright in the installation CD.

    Sorry if it took some time.

     
1 2 > >> (Page 1 of 2)