Blame src/lib/plugin_apis/kbd.h

Packit 2ba279
#include <glib.h>
Packit 2ba279
#include <glib-object.h>
Packit 2ba279
#include <blockdev/utils.h>
Packit 2ba279
Packit 2ba279
Packit 2ba279
#ifndef BD_KBD_API
Packit 2ba279
#define BD_KBD_API
Packit 2ba279
Packit 2ba279
GQuark  bd_kbd_error_quark (void);
Packit 2ba279
Packit 2ba279
Packit 2ba279
#define BD_KBD_ERROR bd_kbd_error_quark ()
Packit 2ba279
typedef enum {
Packit 2ba279
    BD_KBD_ERROR_INVAL,
Packit 2ba279
    BD_KBD_ERROR_KMOD_INIT_FAIL,
Packit 2ba279
    BD_KBD_ERROR_MODULE_FAIL,
Packit 2ba279
    BD_KBD_ERROR_MODULE_NOEXIST,
Packit 2ba279
    BD_KBD_ERROR_ZRAM_NOEXIST,
Packit 2ba279
    BD_KBD_ERROR_ZRAM_INVAL,
Packit 2ba279
    BD_KBD_ERROR_BCACHE_PARSE,
Packit 2ba279
    BD_KBD_ERROR_BCACHE_SETUP_FAIL,
Packit 2ba279
    BD_KBD_ERROR_BCACHE_DETACH_FAIL,
Packit 2ba279
    BD_KBD_ERROR_BCACHE_NOT_ATTACHED,
Packit 2ba279
    BD_KBD_ERROR_BCACHE_UUID,
Packit 2ba279
    BD_KBD_ERROR_BCACHE_MODE_FAIL,
Packit 2ba279
    BD_KBD_ERROR_BCACHE_MODE_INVAL,
Packit 2ba279
    BD_KBD_ERROR_BCACHE_NOEXIST,
Packit 2ba279
    BD_KBD_ERROR_BCACHE_INVAL,
Packit 2ba279
    BD_KBD_ERROR_TECH_UNAVAIL,
Packit 2ba279
} BDKBDError;
Packit 2ba279
Packit 2ba279
typedef enum {
Packit 2ba279
    BD_KBD_MODE_WRITETHROUGH,
Packit 2ba279
    BD_KBD_MODE_WRITEBACK,
Packit 2ba279
    BD_KBD_MODE_WRITEAROUND,
Packit 2ba279
    BD_KBD_MODE_NONE,
Packit 2ba279
    BD_KBD_MODE_UNKNOWN,
Packit 2ba279
} BDKBDBcacheMode;
Packit 2ba279
Packit 2ba279
#define BD_KBD_TYPE_ZRAM_STATS (bd_kbd_zram_stats_get_type ())
Packit 2ba279
GType  bd_kbd_zram_stats_get_type ();
Packit 2ba279
Packit 2ba279
Packit 2ba279
typedef struct BDKBDZramStats {
Packit 2ba279
    guint64 disksize;
Packit 2ba279
    guint64 num_reads;
Packit 2ba279
    guint64 num_writes;
Packit 2ba279
    guint64 invalid_io;
Packit 2ba279
    guint64 zero_pages;
Packit 2ba279
    guint64 max_comp_streams;
Packit 2ba279
    gchar* comp_algorithm;
Packit 2ba279
    guint64 orig_data_size;
Packit 2ba279
    guint64 compr_data_size;
Packit 2ba279
    guint64 mem_used_total;
Packit 2ba279
} BDKBDZramStats;
Packit 2ba279
Packit 2ba279
/**
Packit 2ba279
 * BDKBDZramStats:
Packit 2ba279
 *
Packit 2ba279
 * see zRAM kernel documentation for details
Packit 2ba279
 * (https://www.kernel.org/doc/Documentation/blockdev/zram.txt)
Packit 2ba279
 */
Packit 2ba279
/**
Packit 2ba279
 * bd_kbd_zram_stats_copy: (skip)
Packit 2ba279
 *
Packit 2ba279
 * Creates a new copy of @data.
Packit 2ba279
 */
Packit 2ba279
BDKBDZramStats* bd_kbd_zram_stats_copy (BDKBDZramStats *data);
Packit 2ba279
Packit 2ba279
Packit 2ba279
/**
Packit 2ba279
 * bd_kbd_zram_stats_free: (skip)
Packit 2ba279
 *
Packit 2ba279
 * Frees @data.
Packit 2ba279
 */
Packit 2ba279
void  bd_kbd_zram_stats_free (BDKBDZramStats *data);
Packit 2ba279
Packit 2ba279
Packit 2ba279
Packit 2ba279
#define BD_KBD_TYPE_BCACHE_STATS (bd_kbd_bcache_stats_get_type ())
Packit 2ba279
GType  bd_kbd_bcache_stats_get_type ();
Packit 2ba279
Packit 2ba279
Packit 2ba279
typedef struct BDKBDBcacheStats {
Packit 2ba279
    gchar *state;
Packit 2ba279
    guint64 block_size;
Packit 2ba279
    guint64 cache_size;
Packit 2ba279
    guint64 cache_used;
Packit 2ba279
    guint64 hits;
Packit 2ba279
    guint64 misses;
Packit 2ba279
    guint64 bypass_hits;
Packit 2ba279
    guint64 bypass_misses;
Packit 2ba279
} BDKBDBcacheStats;
Packit 2ba279
Packit 2ba279
/**
Packit 2ba279
 * BDKBDBcacheStats:
Packit 2ba279
 * @state: state of the cache
Packit 2ba279
 * @block_size: block size used by the cache
Packit 2ba279
 * @cache_size: size of the cache
Packit 2ba279
 * @cache_used: size of the used space in the cache
Packit 2ba279
 * @hits: number of hits
Packit 2ba279
 * @misses: number of misses
Packit 2ba279
 * @bypass_hits: number of bypass hits
Packit 2ba279
 * @bypass_misses: number of bypass misses
Packit 2ba279
 */
Packit 2ba279
/**
Packit 2ba279
 * bd_kbd_bcache_stats_copy: (skip)
Packit 2ba279
 *
Packit 2ba279
 * Creates a new copy of @data.
Packit 2ba279
 */
Packit 2ba279
BDKBDBcacheStats* bd_kbd_bcache_stats_copy (BDKBDBcacheStats *data);
Packit 2ba279
Packit 2ba279
Packit 2ba279
/**
Packit 2ba279
 * bd_kbd_bcache_stats_free: (skip)
Packit 2ba279
 *
Packit 2ba279
 * Frees @data.
Packit 2ba279
 */
Packit 2ba279
void  bd_kbd_bcache_stats_free (BDKBDBcacheStats *data);
Packit 2ba279
Packit 2ba279
Packit 2ba279
Packit 2ba279
typedef enum {
Packit 2ba279
    BD_KBD_TECH_ZRAM = 0,
Packit 2ba279
    BD_KBD_TECH_BCACHE,
Packit 2ba279
} BDKBDTech;
Packit 2ba279
Packit 2ba279
typedef enum {
Packit 2ba279
    BD_KBD_TECH_MODE_CREATE  = 1 << 0,
Packit 2ba279
    BD_KBD_TECH_MODE_DESTROY = 1 << 1,
Packit 2ba279
    BD_KBD_TECH_MODE_MODIFY  = 1 << 2,
Packit 2ba279
    BD_KBD_TECH_MODE_QUERY   = 1 << 3,
Packit 2ba279
} BDKBDTechMode;
Packit 2ba279
Packit 2ba279
/**
Packit 2ba279
 * bd_kbd_is_tech_avail:
Packit 2ba279
 * @tech: the queried tech
Packit 2ba279
 * @mode: a bit mask of queried modes of operation (#BDKBDTechMode) for @tech
Packit 2ba279
 * @error: (out): place to store error (details about why the @tech-@mode combination is not available)
Packit 2ba279
 *
Packit 2ba279
 * Returns: whether the @tech-@mode combination is available -- supported by the
Packit 2ba279
 *          plugin implementation and having all the runtime dependencies available
Packit 2ba279
 */
Packit 2ba279
gboolean  bd_kbd_is_tech_avail (BDKBDTech tech, guint64 mode, GError **error);
Packit 2ba279
Packit 2ba279
Packit 2ba279
/**
Packit 2ba279
 * bd_kbd_zram_create_devices:
Packit 2ba279
 * @num_devices: number of devices to create
Packit 2ba279
 * @sizes: (array zero-terminated=1): requested sizes (in bytes) for created zRAM
Packit 2ba279
 *                                    devices
Packit 2ba279
 * @nstreams: (allow-none) (array zero-terminated=1): numbers of streams for created
Packit 2ba279
 *                                                    zRAM devices
Packit 2ba279
 * @error: (out): place to store error (if any)
Packit 2ba279
 *
Packit 2ba279
 * Returns: whether @num_devices zRAM devices were successfully created or not
Packit 2ba279
 *
Packit 2ba279
 * **Lengths of @size and @nstreams (if given) have to be >= @num_devices!**
Packit 2ba279
 *
Packit 2ba279
 * Tech category: %BD_KBD_TECH_ZRAM-%BD_KBD_TECH_MODE_CREATE
Packit 2ba279
 */
Packit 2ba279
gboolean  bd_kbd_zram_create_devices (guint64 num_devices, const guint64 *sizes, const guint64 *nstreams, GError **error);
Packit 2ba279
Packit 2ba279
Packit 2ba279
/**
Packit 2ba279
 * bd_kbd_zram_destroy_devices:
Packit 2ba279
 * @error: (out): place to store error (if any)
Packit 2ba279
 *
Packit 2ba279
 * Returns: whether zRAM devices were successfully destroyed or not
Packit 2ba279
 *
Packit 2ba279
 * The only way how to destroy zRAM device right now is to unload the 'zram'
Packit 2ba279
 * module and thus destroy all of them. That's why this function doesn't allow
Packit 2ba279
 * specification of which devices should be destroyed.
Packit 2ba279
 *
Packit 2ba279
 * Tech category: %BD_KBD_TECH_ZRAM-%BD_KBD_TECH_MODE_DESTROY
Packit 2ba279
 */
Packit 2ba279
gboolean  bd_kbd_zram_destroy_devices (GError **error);
Packit 2ba279
Packit 2ba279
Packit 2ba279
/**
Packit 2ba279
 * bd_kbd_zram_add_device:
Packit 2ba279
 * @size: size of the zRAM device to add
Packit 2ba279
 * @nstreams: number of streams to use for the new device (or 0 to use the defaults)
Packit 2ba279
 * @device: (allow-none) (out): place to store the name of the newly added device
Packit 2ba279
 * @error: (out): place to store error (if any)
Packit 2ba279
 *
Packit 2ba279
 * Returns: whether a new zRAM device was added or not
Packit 2ba279
 *
Packit 2ba279
 * Tech category: %BD_KBD_TECH_ZRAM-%BD_KBD_TECH_MODE_MODIFY
Packit 2ba279
 */
Packit 2ba279
gboolean  bd_kbd_zram_add_device (guint64 size, guint64 nstreams, gchar **device, GError **error);
Packit 2ba279
Packit 2ba279
Packit 2ba279
/**
Packit 2ba279
 * bd_kbd_zram_remove_device:
Packit 2ba279
 * @device: zRAM device to remove
Packit 2ba279
 * @error: (out): place to store error (if any)
Packit 2ba279
 *
Packit 2ba279
 * Returns: whether the @device was successfully removed or not
Packit 2ba279
 *
Packit 2ba279
 * Tech category: %BD_KBD_TECH_ZRAM-%BD_KBD_TECH_MODE_MODIFY
Packit 2ba279
 */
Packit 2ba279
gboolean  bd_kbd_zram_remove_device (const gchar *device, GError **error);
Packit 2ba279
Packit 2ba279
Packit 2ba279
/**
Packit 2ba279
 * bd_kbd_zram_get_stats:
Packit 2ba279
 * @device: zRAM device to get stats for
Packit 2ba279
 * @error: (out): place to store error (if any)
Packit 2ba279
 *
Packit 2ba279
 * Returns: (transfer full): statistics for the zRAM device
Packit 2ba279
 *
Packit 2ba279
 * Tech category: %BD_KBD_TECH_ZRAM-%BD_KBD_TECH_MODE_QUERY
Packit 2ba279
 */
Packit 2ba279
BDKBDZramStats* bd_kbd_zram_get_stats (const gchar *device, GError **error);
Packit 2ba279
Packit 2ba279
Packit 2ba279
/**
Packit 2ba279
 * bd_kbd_bcache_create:
Packit 2ba279
 * @backing_device: backing (slow) device of the cache
Packit 2ba279
 * @cache_device: cache (fast) device of the cache
Packit 2ba279
 * @extra: (allow-none) (array zero-terminated=1): extra options for the creation (right now
Packit 2ba279
 *                                                 passed to the 'make-bcache' utility)
Packit 2ba279
 * @bcache_device: (out) (allow-none) (transfer full): place to store the name of the new bcache device (if any)
Packit 2ba279
 * @error: (out): place to store error (if any)
Packit 2ba279
 *
Packit 2ba279
 * Returns: whether the bcache device was successfully created or not
Packit 2ba279
 *
Packit 2ba279
 * Tech category: %BD_KBD_TECH_BCACHE-%BD_KBD_TECH_MODE_CREATE
Packit 2ba279
 */
Packit 2ba279
gboolean  bd_kbd_bcache_create (const gchar *backing_device, const gchar *cache_device, const BDExtraArg **extra, const gchar **bcache_device, GError **error);
Packit 2ba279
Packit 2ba279
Packit 2ba279
/**
Packit 2ba279
 * bd_kbd_bcache_attach:
Packit 2ba279
 * @c_set_uuid: cache set UUID of the cache to attach
Packit 2ba279
 * @bcache_device: bcache device to attach @c_set_uuid cache to
Packit 2ba279
 * @error: (out): place to store error (if any)
Packit 2ba279
 *
Packit 2ba279
 * Returns: whether the @c_set_uuid cache was successfully attached to @bcache_device or not
Packit 2ba279
 *
Packit 2ba279
 * Tech category: %BD_KBD_TECH_BCACHE-%BD_KBD_TECH_MODE_MODIFY
Packit 2ba279
 */
Packit 2ba279
gboolean  bd_kbd_bcache_attach (const gchar *c_set_uuid, const gchar *bcache_device, GError **error);
Packit 2ba279
Packit 2ba279
Packit 2ba279
/**
Packit 2ba279
 * bd_kbd_bcache_detach:
Packit 2ba279
 * @bcache_device: bcache device to detach the cache from
Packit 2ba279
 * @c_set_uuid: (out) (allow-none) (transfer full): cache set UUID of the detached cache
Packit 2ba279
 * @error: (out): place to store error (if any)
Packit 2ba279
 * Returns: whether the bcache device @bcache_device was successfully destroyed or not
Packit 2ba279
 *
Packit 2ba279
 * Note: Flushes the cache first.
Packit 2ba279
 *
Packit 2ba279
 * Tech category: %BD_KBD_TECH_BCACHE-%BD_KBD_TECH_MODE_MODIFY
Packit 2ba279
 */
Packit 2ba279
gboolean  bd_kbd_bcache_detach (const gchar *bcache_device, gchar **c_set_uuid, GError **error);
Packit 2ba279
Packit 2ba279
Packit 2ba279
/**
Packit 2ba279
 * bd_kbd_bcache_destroy:
Packit 2ba279
 * @bcache_device: bcache device to destroy
Packit 2ba279
 * @error: (out): place to store error (if any)
Packit 2ba279
 *
Packit 2ba279
 * Returns: whether the bcache device @bcache_device was successfully destroyed or not
Packit 2ba279
 *
Packit 2ba279
 * Tech category: %BD_KBD_TECH_BCACHE-%BD_KBD_TECH_MODE_DESTROY
Packit 2ba279
 */
Packit 2ba279
gboolean  bd_kbd_bcache_destroy (const gchar *bcache_device, GError **error);
Packit 2ba279
Packit 2ba279
Packit 2ba279
/**
Packit 2ba279
 * bd_kbd_bcache_get_mode:
Packit 2ba279
 * @bcache_device: device to get mode of
Packit 2ba279
 * @error: (out): place to store error (if any)
Packit 2ba279
 *
Packit 2ba279
 * Returns: current mode of the @bcache_device
Packit 2ba279
 *
Packit 2ba279
 * Tech category: %BD_KBD_TECH_BCACHE-%BD_KBD_TECH_MODE_QUERY
Packit 2ba279
 */
Packit 2ba279
BDKBDBcacheMode  bd_kbd_bcache_get_mode (const gchar *bcache_device, GError **error);
Packit 2ba279
Packit 2ba279
Packit 2ba279
/**
Packit 2ba279
 * bd_kbd_bcache_get_mode_str:
Packit 2ba279
 * @mode: mode to get string representation of
Packit 2ba279
 * @error: (out): place to store error (if any)
Packit 2ba279
 *
Packit 2ba279
 * Returns: (transfer none): string representation of @mode or %NULL in case of error
Packit 2ba279
 *
Packit 2ba279
 * Tech category: always available
Packit 2ba279
 */
Packit 2ba279
const gchar* bd_kbd_bcache_get_mode_str (BDKBDBcacheMode mode, GError **error);
Packit 2ba279
Packit 2ba279
Packit 2ba279
/**
Packit 2ba279
 * bd_kbd_bcache_get_mode_from_str:
Packit 2ba279
 * @mode_str: string representation of mode
Packit 2ba279
 * @error: (out): place to store error (if any)
Packit 2ba279
 *
Packit 2ba279
 * Returns: mode matching the @mode_str given or %BD_KBD_MODE_UNKNOWN in case of no match
Packit 2ba279
 */
Packit 2ba279
BDKBDBcacheMode  bd_kbd_bcache_get_mode_from_str (const gchar *mode_str, GError **error);
Packit 2ba279
Packit 2ba279
Packit 2ba279
/**
Packit 2ba279
 * bd_kbd_bcache_set_mode:
Packit 2ba279
 * @bcache_device: bcache device to set mode of
Packit 2ba279
 * @mode: mode to set
Packit 2ba279
 * @error: (out): place to store error (if any)
Packit 2ba279
 *
Packit 2ba279
 * Returns: whether the mode was successfully set or not
Packit 2ba279
 *
Packit 2ba279
 * Tech category: %BD_KBD_TECH_BCACHE-%BD_KBD_TECH_MODE_MODIFY
Packit 2ba279
 */
Packit 2ba279
gboolean  bd_kbd_bcache_set_mode (const gchar *bcache_device, BDKBDBcacheMode mode, GError **error);
Packit 2ba279
Packit 2ba279
Packit 2ba279
/**
Packit 2ba279
 * bd_kbd_bcache_status:
Packit 2ba279
 * @bcache_device: bcache device to get status for
Packit 2ba279
 * @error: (out): place to store error (if any)
Packit 2ba279
 *
Packit 2ba279
 * Returns: (transfer full): status of the @bcache_device or %NULL in case of
Packit 2ba279
 *                           error (@error is set)
Packit 2ba279
 *
Packit 2ba279
 * Tech category: %BD_KBD_TECH_BCACHE-%BD_KBD_TECH_MODE_QUERY
Packit 2ba279
 */
Packit 2ba279
BDKBDBcacheStats* bd_kbd_bcache_status (const gchar *bcache_device, GError **error);
Packit 2ba279
Packit 2ba279
Packit 2ba279
/**
Packit 2ba279
 * bd_kbd_bcache_get_backing_device:
Packit 2ba279
 * @bcache_device: Bcache device to get the backing device for
Packit 2ba279
 * @error: (out): place to store error (if any)
Packit 2ba279
 *
Packit 2ba279
 * Returns: (transfer full): name of the backing device of the @bcache_device
Packit 2ba279
 *                           or %NULL if failed to determine (@error is populated)
Packit 2ba279
 *
Packit 2ba279
 * Tech category: %BD_KBD_TECH_BCACHE-%BD_KBD_TECH_MODE_QUERY
Packit 2ba279
 */
Packit 2ba279
gchar* bd_kbd_bcache_get_backing_device (const gchar *bcache_device, GError **error);
Packit 2ba279
Packit 2ba279
Packit 2ba279
/**
Packit 2ba279
 * bd_kbd_bcache_get_cache_device:
Packit 2ba279
 * @bcache_device: Bcache device to get the cache device for
Packit 2ba279
 * @error: (out): place to store error (if any)
Packit 2ba279
 *
Packit 2ba279
 * Returns: (transfer full): name of the cache device of the @bcache_device
Packit 2ba279
 *                           or %NULL if failed to determine (@error is populated)
Packit 2ba279
 *
Packit 2ba279
 * Note: returns the name of the first cache device of @bcache_device (in case
Packit 2ba279
 *       there are more)
Packit 2ba279
 *
Packit 2ba279
 * Tech category: %BD_KBD_TECH_BCACHE-%BD_KBD_TECH_MODE_QUERY
Packit 2ba279
 */
Packit 2ba279
gchar* bd_kbd_bcache_get_cache_device (const gchar *bcache_device, GError **error);
Packit 2ba279
Packit 2ba279
Packit 2ba279
#endif  /* BD_KBD_API */