[Patch] UML: Clean up arch/um/drivers/ubd_kern.c - Kernel

This is a discussion on [Patch] UML: Clean up arch/um/drivers/ubd_kern.c - Kernel ; Make some global functions and variables static. And remove some useless declarations for local functions, since we just need to move their definitions ahead. Compile testing passed. Cc: Jeff Dike Signed-off-by: WANG Cong --- arch/um/drivers/ubd_kern.c | 379 +++++++++++++++++++++----------------------- 1 files ...

+ Reply to Thread
Results 1 to 7 of 7

Thread: [Patch] UML: Clean up arch/um/drivers/ubd_kern.c

  1. [Patch] UML: Clean up arch/um/drivers/ubd_kern.c


    Make some global functions and variables static.

    And remove some useless declarations for local functions, since we just
    need to move their definitions ahead.

    Compile testing passed.

    Cc: Jeff Dike
    Signed-off-by: WANG Cong

    ---
    arch/um/drivers/ubd_kern.c | 379 +++++++++++++++++++++-----------------------
    1 files changed, 184 insertions(+), 195 deletions(-)

    diff --git a/arch/um/drivers/ubd_kern.c b/arch/um/drivers/ubd_kern.c
    index be3a279..df5aa37 100644
    --- a/arch/um/drivers/ubd_kern.c
    +++ b/arch/um/drivers/ubd_kern.c
    @@ -72,18 +72,6 @@ struct io_thread_req {
    int error;
    };

    -extern int open_ubd_file(char *file, struct openflags *openflags, int shared,
    - char **backing_file_out, int *bitmap_offset_out,
    - unsigned long *bitmap_len_out, int *data_offset_out,
    - int *create_cow_out);
    -extern int create_cow_file(char *cow_file, char *backing_file,
    - struct openflags flags, int sectorsize,
    - int alignment, int *bitmap_offset_out,
    - unsigned long *bitmap_len_out,
    - int *data_offset_out);
    -extern int read_cow_bitmap(int fd, void *buf, int offset, int len);
    -extern void do_io(struct io_thread_req *req);
    -
    static inline int ubd_test_bit(__u64 bit, unsigned char *data)
    {
    __u64 n;
    @@ -200,7 +188,7 @@ struct ubd {
    }

    /* Protected by ubd_lock */
    -struct ubd ubd_devs[MAX_DEV] = { [ 0 ... MAX_DEV - 1 ] = DEFAULT_UBD };
    +static struct ubd ubd_devs[MAX_DEV] = { [ 0 ... MAX_DEV - 1 ] = DEFAULT_UBD };

    /* Only changed by fake_ide_setup which is a setup */
    static int fake_ide = 0;
    @@ -463,7 +451,7 @@ __uml_help(udb_setup,
    static void do_ubd_request(struct request_queue * q);

    /* Only changed by ubd_init, which is an initcall. */
    -int thread_fd = -1;
    +static int thread_fd = -1;

    static void ubd_end_request(struct request *req, int bytes, int error)
    {
    @@ -531,7 +519,7 @@ static irqreturn_t ubd_intr(int irq, void *dev)
    /* Only changed by ubd_init, which is an initcall. */
    static int io_pid = -1;

    -void kill_io_thread(void)
    +static void kill_io_thread(void)
    {
    if(io_pid != -1)
    os_kill_process(io_pid, 1);
    @@ -547,6 +535,186 @@ static inline int ubd_file_size(struct ubd *ubd_dev, __u64 *size_out)
    return os_file_size(file, size_out);
    }

    +static int read_cow_bitmap(int fd, void *buf, int offset, int len)
    +{
    + int err;
    +
    + err = os_seek_file(fd, offset);
    + if(err < 0)
    + return err;
    +
    + err = os_read_file(fd, buf, len);
    + if(err < 0)
    + return err;
    +
    + return 0;
    +}
    +
    +static int backing_file_mismatch(char *file, __u64 size, time_t mtime)
    +{
    + unsigned long modtime;
    + unsigned long long actual;
    + int err;
    +
    + err = os_file_modtime(file, &modtime);
    + if(err < 0){
    + printk("Failed to get modification time of backing file "
    + "\"%s\", err = %d\n", file, -err);
    + return err;
    + }
    +
    + err = os_file_size(file, &actual);
    + if(err < 0){
    + printk("Failed to get size of backing file \"%s\", "
    + "err = %d\n", file, -err);
    + return err;
    + }
    +
    + if(actual != size){
    + /*__u64 can be a long on AMD64 and with %lu GCC complains; so
    + * the typecast.*/
    + printk("Size mismatch (%llu vs %llu) of COW header vs backing "
    + "file\n", (unsigned long long) size, actual);
    + return -EINVAL;
    + }
    + if(modtime != mtime){
    + printk("mtime mismatch (%ld vs %ld) of COW header vs backing "
    + "file\n", mtime, modtime);
    + return -EINVAL;
    + }
    + return 0;
    +}
    +
    +static int path_requires_switch(char *from_cmdline, char *from_cow, char *cow)
    +{
    + struct uml_stat buf1, buf2;
    + int err;
    +
    + if(from_cmdline == NULL)
    + return 0;
    + if(!strcmp(from_cmdline, from_cow))
    + return 0;
    +
    + err = os_stat_file(from_cmdline, &buf1);
    + if(err < 0){
    + printk("Couldn't stat '%s', err = %d\n", from_cmdline, -err);
    + return 0;
    + }
    + err = os_stat_file(from_cow, &buf2);
    + if(err < 0){
    + printk("Couldn't stat '%s', err = %d\n", from_cow, -err);
    + return 1;
    + }
    + if((buf1.ust_dev == buf2.ust_dev) && (buf1.ust_ino == buf2.ust_ino))
    + return 0;
    +
    + printk("Backing file mismatch - \"%s\" requested,\n"
    + "\"%s\" specified in COW header of \"%s\"\n",
    + from_cmdline, from_cow, cow);
    + return 1;
    +}
    +
    +static int open_ubd_file(char *file, struct openflags *openflags, int shared,
    + char **backing_file_out, int *bitmap_offset_out,
    + unsigned long *bitmap_len_out, int *data_offset_out,
    + int *create_cow_out)
    +{
    + time_t mtime;
    + unsigned long long size;
    + __u32 version, align;
    + char *backing_file;
    + int fd, err, sectorsize, asked_switch, mode = 0644;
    +
    + fd = os_open_file(file, *openflags, mode);
    + if (fd < 0) {
    + if ((fd == -ENOENT) && (create_cow_out != NULL))
    + *create_cow_out = 1;
    + if (!openflags->w ||
    + ((fd != -EROFS) && (fd != -EACCES)))
    + return fd;
    + openflags->w = 0;
    + fd = os_open_file(file, *openflags, mode);
    + if (fd < 0)
    + return fd;
    + }
    +
    + if(shared)
    + printk("Not locking \"%s\" on the host\n", file);
    + else {
    + err = os_lock_file(fd, openflags->w);
    + if(err < 0){
    + printk("Failed to lock '%s', err = %d\n", file, -err);
    + goto out_close;
    + }
    + }
    +
    + /* Successful return case! */
    + if(backing_file_out == NULL)
    + return fd;
    +
    + err = read_cow_header(file_reader, &fd, &version, &backing_file, &mtime,
    + &size, &sectorsize, &align, bitmap_offset_out);
    + if(err && (*backing_file_out != NULL)){
    + printk("Failed to read COW header from COW file \"%s\", "
    + "errno = %d\n", file, -err);
    + goto out_close;
    + }
    + if(err)
    + return fd;
    +
    + asked_switch = path_requires_switch(*backing_file_out, backing_file, file);
    +
    + /* Allow switching only if no mismatch. */
    + if (asked_switch && !backing_file_mismatch(*backing_file_out, size, mtime)) {
    + printk("Switching backing file to '%s'\n", *backing_file_out);
    + err = write_cow_header(file, fd, *backing_file_out,
    + sectorsize, align, &size);
    + if (err) {
    + printk("Switch failed, errno = %d\n", -err);
    + goto out_close;
    + }
    + } else {
    + *backing_file_out = backing_file;
    + err = backing_file_mismatch(*backing_file_out, size, mtime);
    + if (err)
    + goto out_close;
    + }
    +
    + cow_sizes(version, size, sectorsize, align, *bitmap_offset_out,
    + bitmap_len_out, data_offset_out);
    +
    + return fd;
    + out_close:
    + os_close_file(fd);
    + return err;
    +}
    +
    +static int create_cow_file(char *cow_file, char *backing_file,
    + struct openflags flags,
    + int sectorsize, int alignment, int *bitmap_offset_out,
    + unsigned long *bitmap_len_out, int *data_offset_out)
    +{
    + int err, fd;
    +
    + flags.c = 1;
    + fd = open_ubd_file(cow_file, &flags, 0, NULL, NULL, NULL, NULL, NULL);
    + if(fd < 0){
    + err = fd;
    + printk("Open of COW file '%s' failed, errno = %d\n", cow_file,
    + -err);
    + goto out;
    + }
    +
    + err = init_cow_file(fd, cow_file, backing_file, sectorsize, alignment,
    + bitmap_offset_out, bitmap_len_out,
    + data_offset_out);
    + if(!err)
    + return fd;
    + os_close_file(fd);
    + out:
    + return err;
    +}
    +
    static void ubd_close_dev(struct ubd *ubd_dev)
    {
    os_close_file(ubd_dev->fd);
    @@ -1166,185 +1334,6 @@ static int ubd_ioctl(struct inode * inode, struct file * file,
    return -EINVAL;
    }

    -static int path_requires_switch(char *from_cmdline, char *from_cow, char *cow)
    -{
    - struct uml_stat buf1, buf2;
    - int err;
    -
    - if(from_cmdline == NULL)
    - return 0;
    - if(!strcmp(from_cmdline, from_cow))
    - return 0;
    -
    - err = os_stat_file(from_cmdline, &buf1);
    - if(err < 0){
    - printk("Couldn't stat '%s', err = %d\n", from_cmdline, -err);
    - return 0;
    - }
    - err = os_stat_file(from_cow, &buf2);
    - if(err < 0){
    - printk("Couldn't stat '%s', err = %d\n", from_cow, -err);
    - return 1;
    - }
    - if((buf1.ust_dev == buf2.ust_dev) && (buf1.ust_ino == buf2.ust_ino))
    - return 0;
    -
    - printk("Backing file mismatch - \"%s\" requested,\n"
    - "\"%s\" specified in COW header of \"%s\"\n",
    - from_cmdline, from_cow, cow);
    - return 1;
    -}
    -
    -static int backing_file_mismatch(char *file, __u64 size, time_t mtime)
    -{
    - unsigned long modtime;
    - unsigned long long actual;
    - int err;
    -
    - err = os_file_modtime(file, &modtime);
    - if(err < 0){
    - printk("Failed to get modification time of backing file "
    - "\"%s\", err = %d\n", file, -err);
    - return err;
    - }
    -
    - err = os_file_size(file, &actual);
    - if(err < 0){
    - printk("Failed to get size of backing file \"%s\", "
    - "err = %d\n", file, -err);
    - return err;
    - }
    -
    - if(actual != size){
    - /*__u64 can be a long on AMD64 and with %lu GCC complains; so
    - * the typecast.*/
    - printk("Size mismatch (%llu vs %llu) of COW header vs backing "
    - "file\n", (unsigned long long) size, actual);
    - return -EINVAL;
    - }
    - if(modtime != mtime){
    - printk("mtime mismatch (%ld vs %ld) of COW header vs backing "
    - "file\n", mtime, modtime);
    - return -EINVAL;
    - }
    - return 0;
    -}
    -
    -int read_cow_bitmap(int fd, void *buf, int offset, int len)
    -{
    - int err;
    -
    - err = os_seek_file(fd, offset);
    - if(err < 0)
    - return err;
    -
    - err = os_read_file(fd, buf, len);
    - if(err < 0)
    - return err;
    -
    - return 0;
    -}
    -
    -int open_ubd_file(char *file, struct openflags *openflags, int shared,
    - char **backing_file_out, int *bitmap_offset_out,
    - unsigned long *bitmap_len_out, int *data_offset_out,
    - int *create_cow_out)
    -{
    - time_t mtime;
    - unsigned long long size;
    - __u32 version, align;
    - char *backing_file;
    - int fd, err, sectorsize, asked_switch, mode = 0644;
    -
    - fd = os_open_file(file, *openflags, mode);
    - if (fd < 0) {
    - if ((fd == -ENOENT) && (create_cow_out != NULL))
    - *create_cow_out = 1;
    - if (!openflags->w ||
    - ((fd != -EROFS) && (fd != -EACCES)))
    - return fd;
    - openflags->w = 0;
    - fd = os_open_file(file, *openflags, mode);
    - if (fd < 0)
    - return fd;
    - }
    -
    - if(shared)
    - printk("Not locking \"%s\" on the host\n", file);
    - else {
    - err = os_lock_file(fd, openflags->w);
    - if(err < 0){
    - printk("Failed to lock '%s', err = %d\n", file, -err);
    - goto out_close;
    - }
    - }
    -
    - /* Successful return case! */
    - if(backing_file_out == NULL)
    - return fd;
    -
    - err = read_cow_header(file_reader, &fd, &version, &backing_file, &mtime,
    - &size, &sectorsize, &align, bitmap_offset_out);
    - if(err && (*backing_file_out != NULL)){
    - printk("Failed to read COW header from COW file \"%s\", "
    - "errno = %d\n", file, -err);
    - goto out_close;
    - }
    - if(err)
    - return fd;
    -
    - asked_switch = path_requires_switch(*backing_file_out, backing_file, file);
    -
    - /* Allow switching only if no mismatch. */
    - if (asked_switch && !backing_file_mismatch(*backing_file_out, size, mtime)) {
    - printk("Switching backing file to '%s'\n", *backing_file_out);
    - err = write_cow_header(file, fd, *backing_file_out,
    - sectorsize, align, &size);
    - if (err) {
    - printk("Switch failed, errno = %d\n", -err);
    - goto out_close;
    - }
    - } else {
    - *backing_file_out = backing_file;
    - err = backing_file_mismatch(*backing_file_out, size, mtime);
    - if (err)
    - goto out_close;
    - }
    -
    - cow_sizes(version, size, sectorsize, align, *bitmap_offset_out,
    - bitmap_len_out, data_offset_out);
    -
    - return fd;
    - out_close:
    - os_close_file(fd);
    - return err;
    -}
    -
    -int create_cow_file(char *cow_file, char *backing_file, struct openflags flags,
    - int sectorsize, int alignment, int *bitmap_offset_out,
    - unsigned long *bitmap_len_out, int *data_offset_out)
    -{
    - int err, fd;
    -
    - flags.c = 1;
    - fd = open_ubd_file(cow_file, &flags, 0, NULL, NULL, NULL, NULL, NULL);
    - if(fd < 0){
    - err = fd;
    - printk("Open of COW file '%s' failed, errno = %d\n", cow_file,
    - -err);
    - goto out;
    - }
    -
    - err = init_cow_file(fd, cow_file, backing_file, sectorsize, alignment,
    - bitmap_offset_out, bitmap_len_out,
    - data_offset_out);
    - if(!err)
    - return fd;
    - os_close_file(fd);
    - out:
    - return err;
    -}
    -
    static int update_bitmap(struct io_thread_req *req)
    {
    int n;
    @@ -1369,7 +1358,7 @@ static int update_bitmap(struct io_thread_req *req)
    return 0;
    }

    -void do_io(struct io_thread_req *req)
    +static void do_io(struct io_thread_req *req)
    {
    char *buf;
    unsigned long len;
    --
    1.5.2.4

    --
    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/

  2. Re: [Patch] UML: Clean up arch/um/drivers/ubd_kern.c

    These are all fine, except for the mconsole one for which I need some more
    explanation.

    Jeff

    --
    Work email - jdike at linux dot intel dot com
    --
    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/

  3. Re: [Patch] UML: Clean up arch/um/drivers/ubd_kern.c

    On Sun, 13 Apr 2008 00:55:59 +0800 (CST) WANG Cong wrote:

    > Make some global functions and variables static.
    >
    > And remove some useless declarations for local functions, since we just
    > need to move their definitions ahead.


    omg, when checkpatch bit into this patch my CPU melted.

    ho hum.
    --
    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/

  4. Re: [Patch] UML: Clean up arch/um/drivers/ubd_kern.c

    On Mon, Apr 14, 2008 at 11:42:37PM -0700, Andrew Morton wrote:
    > omg, when checkpatch bit into this patch my CPU melted.


    Yeah, I've been scared to do a checkpatch run over that file. I think
    it's the only core file left in UML which hasn't been tidied. Sorry.

    Drop this one, and I'll send a another one which at least is tidied up
    around the changed areas.

    Jeff

    --
    Work email - jdike at linux dot intel dot com
    --
    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/

  5. Re: [Patch] UML: Clean up arch/um/drivers/ubd_kern.c

    From: Jeff Dike
    Date: Tue, 15 Apr 2008 09:33:25 -0400
    > On Mon, Apr 14, 2008 at 11:42:37PM -0700, Andrew Morton wrote:
    > > omg, when checkpatch bit into this patch my CPU melted.

    >
    > Yeah, I've been scared to do a checkpatch run over that file. I think
    > it's the only core file left in UML which hasn't been tidied. Sorry.


    Oh, I thought I have checked all the patch with checkpatch.pl, it seems
    that this one was missing. Sorry. ;(

    >
    > Drop this one, and I'll send a another one which at least is tidied up
    > around the changed areas.
    >


    Please feel free to do that.

    --
    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/

  6. Re: [Patch] UML: Clean up arch/um/drivers/ubd_kern.c

    On Wed, Apr 16, 2008 at 01:39:19PM +0800, WANG Cong wrote:
    > From: Jeff Dike
    > Date: Tue, 15 Apr 2008 09:33:25 -0400
    > > On Mon, Apr 14, 2008 at 11:42:37PM -0700, Andrew Morton wrote:
    > > > omg, when checkpatch bit into this patch my CPU melted.


    Here's a cleaned up version.

    Jeff


    From: WANG Cong

    Make some global functions and variables static.

    And remove some useless declarations for local functions, since we just
    need to move their definitions ahead.

    Compile testing passed.

    [ jdike - checkpatch cleanups ]

    Signed-off-by: WANG Cong
    Signed-off-by: Jeff Dike

    Index: linux-2.6.22/arch/um/drivers/ubd_kern.c
    ================================================== =================
    --- linux-2.6.22.orig/arch/um/drivers/ubd_kern.c 2008-04-14 10:44:36.000000000 -0400
    +++ linux-2.6.22/arch/um/drivers/ubd_kern.c 2008-04-16 11:17:12.000000000 -0400
    @@ -72,18 +72,6 @@ struct io_thread_req {
    int error;
    };

    -extern int open_ubd_file(char *file, struct openflags *openflags, int shared,
    - char **backing_file_out, int *bitmap_offset_out,
    - unsigned long *bitmap_len_out, int *data_offset_out,
    - int *create_cow_out);
    -extern int create_cow_file(char *cow_file, char *backing_file,
    - struct openflags flags, int sectorsize,
    - int alignment, int *bitmap_offset_out,
    - unsigned long *bitmap_len_out,
    - int *data_offset_out);
    -extern int read_cow_bitmap(int fd, void *buf, int offset, int len);
    -extern void do_io(struct io_thread_req *req);
    -
    static inline int ubd_test_bit(__u64 bit, unsigned char *data)
    {
    __u64 n;
    @@ -200,7 +188,7 @@ struct ubd {
    }

    /* Protected by ubd_lock */
    -struct ubd ubd_devs[MAX_DEV] = { [ 0 ... MAX_DEV - 1 ] = DEFAULT_UBD };
    +static struct ubd ubd_devs[MAX_DEV] = { [0 ... MAX_DEV - 1] = DEFAULT_UBD };

    /* Only changed by fake_ide_setup which is a setup */
    static int fake_ide = 0;
    @@ -463,7 +451,7 @@ __uml_help(udb_setup,
    static void do_ubd_request(struct request_queue * q);

    /* Only changed by ubd_init, which is an initcall. */
    -int thread_fd = -1;
    +static int thread_fd = -1;

    static void ubd_end_request(struct request *req, int bytes, int error)
    {
    @@ -531,7 +519,7 @@ static irqreturn_t ubd_intr(int irq, voi
    /* Only changed by ubd_init, which is an initcall. */
    static int io_pid = -1;

    -void kill_io_thread(void)
    +static void kill_io_thread(void)
    {
    if(io_pid != -1)
    os_kill_process(io_pid, 1);
    @@ -547,6 +535,192 @@ static inline int ubd_file_size(struct u
    return os_file_size(file, size_out);
    }

    +static int read_cow_bitmap(int fd, void *buf, int offset, int len)
    +{
    + int err;
    +
    + err = os_seek_file(fd, offset);
    + if (err < 0)
    + return err;
    +
    + err = os_read_file(fd, buf, len);
    + if (err < 0)
    + return err;
    +
    + return 0;
    +}
    +
    +static int backing_file_mismatch(char *file, __u64 size, time_t mtime)
    +{
    + unsigned long modtime;
    + unsigned long long actual;
    + int err;
    +
    + err = os_file_modtime(file, &modtime);
    + if (err < 0) {
    + printk(KERN_ERR "Failed to get modification time of backing "
    + "file \"%s\", err = %d\n", file, -err);
    + return err;
    + }
    +
    + err = os_file_size(file, &actual);
    + if (err < 0) {
    + printk(KERN_ERR "Failed to get size of backing file \"%s\", "
    + "err = %d\n", file, -err);
    + return err;
    + }
    +
    + if (actual != size) {
    + /*__u64 can be a long on AMD64 and with %lu GCC complains; so
    + * the typecast.*/
    + printk(KERN_ERR "Size mismatch (%llu vs %llu) of COW header "
    + "vs backing file\n", (unsigned long long) size, actual);
    + return -EINVAL;
    + }
    + if (modtime != mtime) {
    + printk(KERN_ERR "mtime mismatch (%ld vs %ld) of COW header vs "
    + "backing file\n", mtime, modtime);
    + return -EINVAL;
    + }
    + return 0;
    +}
    +
    +static int path_requires_switch(char *from_cmdline, char *from_cow, char *cow)
    +{
    + struct uml_stat buf1, buf2;
    + int err;
    +
    + if (from_cmdline == NULL)
    + return 0;
    + if (!strcmp(from_cmdline, from_cow))
    + return 0;
    +
    + err = os_stat_file(from_cmdline, &buf1);
    + if (err < 0) {
    + printk(KERN_ERR "Couldn't stat '%s', err = %d\n", from_cmdline,
    + -err);
    + return 0;
    + }
    + err = os_stat_file(from_cow, &buf2);
    + if (err < 0) {
    + printk(KERN_ERR "Couldn't stat '%s', err = %d\n", from_cow,
    + -err);
    + return 1;
    + }
    + if ((buf1.ust_dev == buf2.ust_dev) && (buf1.ust_ino == buf2.ust_ino))
    + return 0;
    +
    + printk(KERN_ERR "Backing file mismatch - \"%s\" requested, "
    + "\"%s\" specified in COW header of \"%s\"\n",
    + from_cmdline, from_cow, cow);
    + return 1;
    +}
    +
    +static int open_ubd_file(char *file, struct openflags *openflags, int shared,
    + char **backing_file_out, int *bitmap_offset_out,
    + unsigned long *bitmap_len_out, int *data_offset_out,
    + int *create_cow_out)
    +{
    + time_t mtime;
    + unsigned long long size;
    + __u32 version, align;
    + char *backing_file;
    + int fd, err, sectorsize, asked_switch, mode = 0644;
    +
    + fd = os_open_file(file, *openflags, mode);
    + if (fd < 0) {
    + if ((fd == -ENOENT) && (create_cow_out != NULL))
    + *create_cow_out = 1;
    + if (!openflags->w ||
    + ((fd != -EROFS) && (fd != -EACCES)))
    + return fd;
    + openflags->w = 0;
    + fd = os_open_file(file, *openflags, mode);
    + if (fd < 0)
    + return fd;
    + }
    +
    + if (shared)
    + printk(KERN_INFO "Not locking \"%s\" on the host\n", file);
    + else {
    + err = os_lock_file(fd, openflags->w);
    + if (err < 0) {
    + printk(KERN_ERR "Failed to lock '%s', err = %d\n",
    + file, -err);
    + goto out_close;
    + }
    + }
    +
    + /* Successful return case! */
    + if (backing_file_out == NULL)
    + return fd;
    +
    + err = read_cow_header(file_reader, &fd, &version, &backing_file, &mtime,
    + &size, &sectorsize, &align, bitmap_offset_out);
    + if (err && (*backing_file_out != NULL)) {
    + printk(KERN_ERR "Failed to read COW header from COW file "
    + "\"%s\", errno = %d\n", file, -err);
    + goto out_close;
    + }
    + if (err)
    + return fd;
    +
    + asked_switch = path_requires_switch(*backing_file_out, backing_file,
    + file);
    +
    + /* Allow switching only if no mismatch. */
    + if (asked_switch && !backing_file_mismatch(*backing_file_out, size,
    + mtime)) {
    + printk(KERN_ERR "Switching backing file to '%s'\n",
    + *backing_file_out);
    + err = write_cow_header(file, fd, *backing_file_out,
    + sectorsize, align, &size);
    + if (err) {
    + printk(KERN_ERR "Switch failed, errno = %d\n", -err);
    + goto out_close;
    + }
    + } else {
    + *backing_file_out = backing_file;
    + err = backing_file_mismatch(*backing_file_out, size, mtime);
    + if (err)
    + goto out_close;
    + }
    +
    + cow_sizes(version, size, sectorsize, align, *bitmap_offset_out,
    + bitmap_len_out, data_offset_out);
    +
    + return fd;
    + out_close:
    + os_close_file(fd);
    + return err;
    +}
    +
    +static int create_cow_file(char *cow_file, char *backing_file,
    + struct openflags flags,
    + int sectorsize, int alignment, int *bitmap_offset_out,
    + unsigned long *bitmap_len_out, int *data_offset_out)
    +{
    + int err, fd;
    +
    + flags.c = 1;
    + fd = open_ubd_file(cow_file, &flags, 0, NULL, NULL, NULL, NULL, NULL);
    + if (fd < 0) {
    + err = fd;
    + printk(KERN_ERR "Open of COW file '%s' failed, errno = %d\n",
    + cow_file, -err);
    + goto out;
    + }
    +
    + err = init_cow_file(fd, cow_file, backing_file, sectorsize, alignment,
    + bitmap_offset_out, bitmap_len_out,
    + data_offset_out);
    + if (!err)
    + return fd;
    + os_close_file(fd);
    + out:
    + return err;
    +}
    +
    static void ubd_close_dev(struct ubd *ubd_dev)
    {
    os_close_file(ubd_dev->fd);
    @@ -1166,185 +1340,6 @@ static int ubd_ioctl(struct inode * inod
    return -EINVAL;
    }

    -static int path_requires_switch(char *from_cmdline, char *from_cow, char *cow)
    -{
    - struct uml_stat buf1, buf2;
    - int err;
    -
    - if(from_cmdline == NULL)
    - return 0;
    - if(!strcmp(from_cmdline, from_cow))
    - return 0;
    -
    - err = os_stat_file(from_cmdline, &buf1);
    - if(err < 0){
    - printk("Couldn't stat '%s', err = %d\n", from_cmdline, -err);
    - return 0;
    - }
    - err = os_stat_file(from_cow, &buf2);
    - if(err < 0){
    - printk("Couldn't stat '%s', err = %d\n", from_cow, -err);
    - return 1;
    - }
    - if((buf1.ust_dev == buf2.ust_dev) && (buf1.ust_ino == buf2.ust_ino))
    - return 0;
    -
    - printk("Backing file mismatch - \"%s\" requested,\n"
    - "\"%s\" specified in COW header of \"%s\"\n",
    - from_cmdline, from_cow, cow);
    - return 1;
    -}
    -
    -static int backing_file_mismatch(char *file, __u64 size, time_t mtime)
    -{
    - unsigned long modtime;
    - unsigned long long actual;
    - int err;
    -
    - err = os_file_modtime(file, &modtime);
    - if(err < 0){
    - printk("Failed to get modification time of backing file "
    - "\"%s\", err = %d\n", file, -err);
    - return err;
    - }
    -
    - err = os_file_size(file, &actual);
    - if(err < 0){
    - printk("Failed to get size of backing file \"%s\", "
    - "err = %d\n", file, -err);
    - return err;
    - }
    -
    - if(actual != size){
    - /*__u64 can be a long on AMD64 and with %lu GCC complains; so
    - * the typecast.*/
    - printk("Size mismatch (%llu vs %llu) of COW header vs backing "
    - "file\n", (unsigned long long) size, actual);
    - return -EINVAL;
    - }
    - if(modtime != mtime){
    - printk("mtime mismatch (%ld vs %ld) of COW header vs backing "
    - "file\n", mtime, modtime);
    - return -EINVAL;
    - }
    - return 0;
    -}
    -
    -int read_cow_bitmap(int fd, void *buf, int offset, int len)
    -{
    - int err;
    -
    - err = os_seek_file(fd, offset);
    - if(err < 0)
    - return err;
    -
    - err = os_read_file(fd, buf, len);
    - if(err < 0)
    - return err;
    -
    - return 0;
    -}
    -
    -int open_ubd_file(char *file, struct openflags *openflags, int shared,
    - char **backing_file_out, int *bitmap_offset_out,
    - unsigned long *bitmap_len_out, int *data_offset_out,
    - int *create_cow_out)
    -{
    - time_t mtime;
    - unsigned long long size;
    - __u32 version, align;
    - char *backing_file;
    - int fd, err, sectorsize, asked_switch, mode = 0644;
    -
    - fd = os_open_file(file, *openflags, mode);
    - if (fd < 0) {
    - if ((fd == -ENOENT) && (create_cow_out != NULL))
    - *create_cow_out = 1;
    - if (!openflags->w ||
    - ((fd != -EROFS) && (fd != -EACCES)))
    - return fd;
    - openflags->w = 0;
    - fd = os_open_file(file, *openflags, mode);
    - if (fd < 0)
    - return fd;
    - }
    -
    - if(shared)
    - printk("Not locking \"%s\" on the host\n", file);
    - else {
    - err = os_lock_file(fd, openflags->w);
    - if(err < 0){
    - printk("Failed to lock '%s', err = %d\n", file, -err);
    - goto out_close;
    - }
    - }
    -
    - /* Successful return case! */
    - if(backing_file_out == NULL)
    - return fd;
    -
    - err = read_cow_header(file_reader, &fd, &version, &backing_file, &mtime,
    - &size, &sectorsize, &align, bitmap_offset_out);
    - if(err && (*backing_file_out != NULL)){
    - printk("Failed to read COW header from COW file \"%s\", "
    - "errno = %d\n", file, -err);
    - goto out_close;
    - }
    - if(err)
    - return fd;
    -
    - asked_switch = path_requires_switch(*backing_file_out, backing_file, file);
    -
    - /* Allow switching only if no mismatch. */
    - if (asked_switch && !backing_file_mismatch(*backing_file_out, size, mtime)) {
    - printk("Switching backing file to '%s'\n", *backing_file_out);
    - err = write_cow_header(file, fd, *backing_file_out,
    - sectorsize, align, &size);
    - if (err) {
    - printk("Switch failed, errno = %d\n", -err);
    - goto out_close;
    - }
    - } else {
    - *backing_file_out = backing_file;
    - err = backing_file_mismatch(*backing_file_out, size, mtime);
    - if (err)
    - goto out_close;
    - }
    -
    - cow_sizes(version, size, sectorsize, align, *bitmap_offset_out,
    - bitmap_len_out, data_offset_out);
    -
    - return fd;
    - out_close:
    - os_close_file(fd);
    - return err;
    -}
    -
    -int create_cow_file(char *cow_file, char *backing_file, struct openflags flags,
    - int sectorsize, int alignment, int *bitmap_offset_out,
    - unsigned long *bitmap_len_out, int *data_offset_out)
    -{
    - int err, fd;
    -
    - flags.c = 1;
    - fd = open_ubd_file(cow_file, &flags, 0, NULL, NULL, NULL, NULL, NULL);
    - if(fd < 0){
    - err = fd;
    - printk("Open of COW file '%s' failed, errno = %d\n", cow_file,
    - -err);
    - goto out;
    - }
    -
    - err = init_cow_file(fd, cow_file, backing_file, sectorsize, alignment,
    - bitmap_offset_out, bitmap_len_out,
    - data_offset_out);
    - if(!err)
    - return fd;
    - os_close_file(fd);
    - out:
    - return err;
    -}
    -
    static int update_bitmap(struct io_thread_req *req)
    {
    int n;
    @@ -1369,7 +1364,7 @@ static int update_bitmap(struct io_threa
    return 0;
    }

    -void do_io(struct io_thread_req *req)
    +static void do_io(struct io_thread_req *req)
    {
    char *buf;
    unsigned long len;
    --
    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/

  7. Re: [Patch] UML: Clean up arch/um/drivers/ubd_kern.c

    From: Jeff Dike
    Date: Wed, 16 Apr 2008 11:20:19 -0400
    > On Wed, Apr 16, 2008 at 01:39:19PM +0800, WANG Cong wrote:
    > > From: Jeff Dike
    > > Date: Tue, 15 Apr 2008 09:33:25 -0400
    > > > On Mon, Apr 14, 2008 at 11:42:37PM -0700, Andrew Morton wrote:
    > > > > omg, when checkpatch bit into this patch my CPU melted.

    >
    > Here's a cleaned up version.
    >
    > Jeff


    Looks OK for me. Thank you!
    --
    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/

+ Reply to Thread