Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * reservations.h
0004  *
0005  * Allocation reservations function prototypes and structures.
0006  *
0007  * Copyright (C) 2010 Novell.  All rights reserved.
0008  */
0009 
0010 #ifndef OCFS2_RESERVATIONS_H
0011 #define OCFS2_RESERVATIONS_H
0012 
0013 #include <linux/rbtree.h>
0014 
0015 #define OCFS2_DEFAULT_RESV_LEVEL    2
0016 #define OCFS2_MAX_RESV_LEVEL    9
0017 #define OCFS2_MIN_RESV_LEVEL    0
0018 
0019 struct ocfs2_alloc_reservation {
0020     struct rb_node  r_node;
0021 
0022     unsigned int    r_start;    /* Beginning of current window */
0023     unsigned int    r_len;      /* Length of the window */
0024 
0025     unsigned int    r_last_len; /* Length of most recent alloc */
0026     unsigned int    r_last_start;   /* Start of most recent alloc */
0027     struct list_head    r_lru;  /* LRU list head */
0028 
0029     unsigned int    r_flags;
0030 };
0031 
0032 #define OCFS2_RESV_FLAG_INUSE   0x01    /* Set when r_node is part of a btree */
0033 #define OCFS2_RESV_FLAG_TMP 0x02    /* Temporary reservation, will be
0034                      * destroyed immedately after use */
0035 #define OCFS2_RESV_FLAG_DIR 0x04    /* Reservation is for an unindexed
0036                      * directory btree */
0037 
0038 struct ocfs2_reservation_map {
0039     struct rb_root      m_reservations;
0040     char            *m_disk_bitmap;
0041 
0042     struct ocfs2_super  *m_osb;
0043 
0044     /* The following are not initialized to meaningful values until a disk
0045      * bitmap is provided. */
0046     u32         m_bitmap_len;   /* Number of valid
0047                          * bits available */
0048 
0049     struct list_head    m_lru;      /* LRU of reservations
0050                          * structures. */
0051 
0052 };
0053 
0054 void ocfs2_resv_init_once(struct ocfs2_alloc_reservation *resv);
0055 
0056 #define OCFS2_RESV_TYPES    (OCFS2_RESV_FLAG_TMP|OCFS2_RESV_FLAG_DIR)
0057 void ocfs2_resv_set_type(struct ocfs2_alloc_reservation *resv,
0058              unsigned int flags);
0059 
0060 int ocfs2_dir_resv_allowed(struct ocfs2_super *osb);
0061 
0062 /**
0063  * ocfs2_resv_discard() - truncate a reservation
0064  * @resmap:
0065  * @resv: the reservation to truncate.
0066  *
0067  * After this function is called, the reservation will be empty, and
0068  * unlinked from the rbtree.
0069  */
0070 void ocfs2_resv_discard(struct ocfs2_reservation_map *resmap,
0071             struct ocfs2_alloc_reservation *resv);
0072 
0073 
0074 /**
0075  * ocfs2_resmap_init() - Initialize fields of a reservations bitmap
0076  * @osb: struct ocfs2_super to be saved in resmap
0077  * @resmap: struct ocfs2_reservation_map to initialize
0078  */
0079 void ocfs2_resmap_init(struct ocfs2_super *osb,
0080               struct ocfs2_reservation_map *resmap);
0081 
0082 /**
0083  * ocfs2_resmap_restart() - "restart" a reservation bitmap
0084  * @resmap: reservations bitmap
0085  * @clen: Number of valid bits in the bitmap
0086  * @disk_bitmap: the disk bitmap this resmap should refer to.
0087  *
0088  * Re-initialize the parameters of a reservation bitmap. This is
0089  * useful for local alloc window slides.
0090  *
0091  * This function will call ocfs2_trunc_resv against all existing
0092  * reservations. A future version will recalculate existing
0093  * reservations based on the new bitmap.
0094  */
0095 void ocfs2_resmap_restart(struct ocfs2_reservation_map *resmap,
0096               unsigned int clen, char *disk_bitmap);
0097 
0098 /**
0099  * ocfs2_resmap_uninit() - uninitialize a reservation bitmap structure
0100  * @resmap: the struct ocfs2_reservation_map to uninitialize
0101  */
0102 void ocfs2_resmap_uninit(struct ocfs2_reservation_map *resmap);
0103 
0104 /**
0105  * ocfs2_resmap_resv_bits() - Return still-valid reservation bits
0106  * @resmap: reservations bitmap
0107  * @resv: reservation to base search from
0108  * @cstart: start of proposed allocation
0109  * @clen: length (in clusters) of proposed allocation
0110  *
0111  * Using the reservation data from resv, this function will compare
0112  * resmap and resmap->m_disk_bitmap to determine what part (if any) of
0113  * the reservation window is still clear to use. If resv is empty,
0114  * this function will try to allocate a window for it.
0115  *
0116  * On success, zero is returned and the valid allocation area is set in cstart
0117  * and clen.
0118  *
0119  * Returns -ENOSPC if reservations are disabled.
0120  */
0121 int ocfs2_resmap_resv_bits(struct ocfs2_reservation_map *resmap,
0122                struct ocfs2_alloc_reservation *resv,
0123                int *cstart, int *clen);
0124 
0125 /**
0126  * ocfs2_resmap_claimed_bits() - Tell the reservation code that bits were used.
0127  * @resmap: reservations bitmap
0128  * @resv: optional reservation to recalulate based on new bitmap
0129  * @cstart: start of allocation in clusters
0130  * @clen: end of allocation in clusters.
0131  *
0132  * Tell the reservation code that bits were used to fulfill allocation in
0133  * resmap. The bits don't have to have been part of any existing
0134  * reservation. But we must always call this function when bits are claimed.
0135  * Internally, the reservations code will use this information to mark the
0136  * reservations bitmap. If resv is passed, it's next allocation window will be
0137  * calculated. It also expects that 'cstart' is the same as we passed back
0138  * from ocfs2_resmap_resv_bits().
0139  */
0140 void ocfs2_resmap_claimed_bits(struct ocfs2_reservation_map *resmap,
0141                    struct ocfs2_alloc_reservation *resv,
0142                    u32 cstart, u32 clen);
0143 
0144 #endif  /* OCFS2_RESERVATIONS_H */