Skip to content
  • Emanuele Giuseppe Esposito's avatar
    3b491a90
    include/block/block: split header into I/O and global state API · 3b491a90
    Emanuele Giuseppe Esposito authored
    
    
    block.h currently contains a mix of functions:
    some of them run under the BQL and modify the block layer graph,
    others are instead thread-safe and perform I/O in iothreads.
    Some others can only be called by either the main loop or the
    iothread running the AioContext (and not other iothreads),
    and using them in another thread would cause deadlocks, and therefore
    it is not ideal to define them as I/O.
    
    It is not easy to understand which function is part of which
    group (I/O vs GS vs "I/O or GS"), and this patch aims to clarify it.
    
    The "GS" functions need the BQL, and often use
    aio_context_acquire/release and/or drain to be sure they
    can modify the graph safely.
    The I/O function are instead thread safe, and can run in
    any AioContext.
    "I/O or GS" functions run instead in the main loop or in
    a single iothread, and use BDRV_POLL_WHILE().
    
    By splitting the header in two files, block-io.h
    and block-global-state.h we have a clearer view on what
    needs what kind of protection. block-common.h
    contains common structures shared by both headers.
    
    block.h is left there for legacy and to avoid changing
    all includes in all c files that use the block APIs.
    
    Assertions are added in the next patch.
    
    Signed-off-by: default avatarEmanuele Giuseppe Esposito <eesposit@redhat.com>
    Message-Id: <20220303151616.325444-4-eesposit@redhat.com>
    Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
    3b491a90
    include/block/block: split header into I/O and global state API
    Emanuele Giuseppe Esposito authored
    
    
    block.h currently contains a mix of functions:
    some of them run under the BQL and modify the block layer graph,
    others are instead thread-safe and perform I/O in iothreads.
    Some others can only be called by either the main loop or the
    iothread running the AioContext (and not other iothreads),
    and using them in another thread would cause deadlocks, and therefore
    it is not ideal to define them as I/O.
    
    It is not easy to understand which function is part of which
    group (I/O vs GS vs "I/O or GS"), and this patch aims to clarify it.
    
    The "GS" functions need the BQL, and often use
    aio_context_acquire/release and/or drain to be sure they
    can modify the graph safely.
    The I/O function are instead thread safe, and can run in
    any AioContext.
    "I/O or GS" functions run instead in the main loop or in
    a single iothread, and use BDRV_POLL_WHILE().
    
    By splitting the header in two files, block-io.h
    and block-global-state.h we have a clearer view on what
    needs what kind of protection. block-common.h
    contains common structures shared by both headers.
    
    block.h is left there for legacy and to avoid changing
    all includes in all c files that use the block APIs.
    
    Assertions are added in the next patch.
    
    Signed-off-by: default avatarEmanuele Giuseppe Esposito <eesposit@redhat.com>
    Message-Id: <20220303151616.325444-4-eesposit@redhat.com>
    Signed-off-by: default avatarKevin Wolf <kwolf@redhat.com>
Loading