Skip to content

Proposal: Add support for disks with custom block ops#303

Merged
tavip merged 2 commits intolkl:masterfrom
petrosagg:custom-blk-dev-ops
Jan 26, 2017
Merged

Proposal: Add support for disks with custom block ops#303
tavip merged 2 commits intolkl:masterfrom
petrosagg:custom-blk-dev-ops

Conversation

@petrosagg
Copy link
Copy Markdown

@petrosagg petrosagg commented Jan 19, 2017

Introduce a new function, lkl_disk_add2, that accepts one more
parameter than the original lkl_disk_add which allows the caller to use
a custom way of serving block requests.

lkl_disk_add is implemented as a trivial case for lkl_disk_add2 by
passing the default ops in order to not break existing users.


This change is Reviewable

@lkl-jenkins
Copy link
Copy Markdown

Can one of the admins verify this patch?

@tavip
Copy link
Copy Markdown
Member

tavip commented Jan 19, 2017

This is for adding support for other (then raw) disk image types, like qcow, right?

I think we should add the custom ops at the end of the lkl_disk structure, just like we do on the netdev side. That way we will not break the API. And in lkl_disk_add, if the ops field is null we can initialize it with the default ops.

Also, if you plan to add support for other disk image types, could you please take a look at how we did it for netdev and see if it fits?

@petrosagg
Copy link
Copy Markdown
Author

petrosagg commented Jan 20, 2017

@tavip Yes, this is to support things lke qcow images or encrypted images or (in my case) network backed images.

I changed my implementation to what you propose by adding a custom ops field at the end of the lkl_disk structure but during testing I found that it does change the API. Consider the following code which works with current LKL but breaks if we add an ops field at the end of lkl_disk.

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include <lkl.h>

int main()
{
    struct lkl_disk *bar;
    void *foo;

    foo = malloc(1024);
    memset(foo, '@', 1024);
    free(foo);

    bar = malloc(sizeof(struct lkl_disk));
    printf("bar->ops = %p\n", bar->ops);
}

Running this prints bar->ops = 0x4040404040404040 instead of (nil).

@tavip
Copy link
Copy Markdown
Member

tavip commented Jan 22, 2017

Sorry for the delay.

You are right :) The safe way would be to go with your proposal, but since we don't have too many users, I wonder if should break the API now in order to have a cleaner set of APIs in the future?

@Rondom @M1cha what do you think?

@M1cha
Copy link
Copy Markdown

M1cha commented Jan 22, 2017

@tavip the AUR says 'Required by (0)' and in UEFI everything is being linked statically anyway. So if you ask me you can break binary compatibility as often as you want :)

@Rondom
Copy link
Copy Markdown

Rondom commented Jan 22, 2017

If there is a valid reason (as in this case), I think one can break the API as necessary. LKL does not publish releases nor is it widespread enough yet that one needs to be overly careful.

Extend `struct lkl_disk` to enable mounting disks that require special
handling of read/write requests like qcow images, encrypted block
devices, or network images.

If `ops` is NULL liblkl will use the default platform ops in order to
not break existing users.

Signed-off-by: Petros Angelatos <petrosagg@gmail.com>
@petrosagg
Copy link
Copy Markdown
Author

@tavip Sounds good. I changed the PR to your suggested implementation

@tavip
Copy link
Copy Markdown
Member

tavip commented Jan 23, 2017

@lkl-jenkins: test this please

Copy link
Copy Markdown
Member

@tavip tavip left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you mentioned, this breaks the API, and we need to initialize the .ops field to NULL in the following apps: fs2tar.c, tests/boot.c and cptofs.c. lklfuse is fine, since there the lkl_disk is not allocated on stack but globally.

Signed-off-by: Petros Angelatos <petrosagg@gmail.com>
@petrosagg
Copy link
Copy Markdown
Author

@tavip fixed

@tavip
Copy link
Copy Markdown
Member

tavip commented Jan 26, 2017

@lkl-jenkins: test this please

@tavip tavip merged commit 44336b1 into lkl:master Jan 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants