Permalink
Browse files

implement function to return avaiable space in tier (maxUsed - used)

  • Loading branch information...
1 parent 6e45e66 commit 96543515d68f75f4d91b52fa65e672938457a918 @tomato42 committed Aug 2, 2012
Showing with 90 additions and 16 deletions.
  1. +37 −0 config.c
  2. +11 −0 config.h
  3. +26 −0 extents.c
  4. +8 −0 extents.h
  5. +4 −3 lvmls.c
  6. +4 −3 lvmls.h
  7. +0 −10 lvmtsd.c
View
@@ -53,6 +53,43 @@ get_score_scaling_factor(struct program_params *pp, const char *lv_name)
"timeExponent");
}
+const char *
+get_volume_lv(struct program_params *pp, const char *lv_name)
+{
+ cfg_t *tmp = cfg_gettsec(pp->cfg, "volume", lv_name);
+ assert(tmp);
+
+ return cfg_getstr(tmp, "LogicalVolume");
+}
+
+const char *
+get_volume_vg(struct program_params *pp, const char *lv_name)
+{
+ cfg_t *tmp = cfg_gettsec(pp->cfg, "volume", lv_name);
+ assert(tmp);
+
+ return cfg_getstr(tmp, "VolumeGroup");
+}
+
+long int
+get_max_space_tier(struct program_params *pp, const char *lv_name,
+ int tier)
+{
+ cfg_t *tmp = cfg_gettsec(pp->cfg, "volume", lv_name);
+ assert(tmp);
+
+ cfg_t *pv_cfg;
+
+ for(size_t i=0; i < cfg_size(tmp, "pv"); i++) {
+ pv_cfg = cfg_getnsec(tmp, "pv", i);
+ if (cfg_getint(pv_cfg, "tier") == tier) {
+ return cfg_getint(pv_cfg, "maxUsedSpace");
+ }
+ }
+
+ return -1;
+}
+
int
lower_tiers_exist(struct program_params *pp, const char *lv_name, int tier)
{
View
@@ -46,7 +46,18 @@ int lower_tiers_exist(struct program_params *pp, const char *lv_name, int tier);
int higher_tiers_exist(struct program_params *pp, const char *lv_name, int tier);
/**
+ * Return max used space on tier by volume
+ */
+long int get_max_space_tier(struct program_params *pp, const char *lv_name,
+ int tier);
+
+/**
* read configuration file
*/
int read_config(struct program_params *pp);
+
+const char *get_volume_lv(struct program_params *pp, const char *lv_name);
+
+const char *get_volume_vg(struct program_params *pp, const char *lv_name);
+
#endif
View
@@ -17,6 +17,7 @@
*/
#include <stdlib.h>
#include <assert.h>
+#include "lvmls.h"
#include "extents.h"
#include "config.h"
@@ -139,3 +140,28 @@ get_extent_tier(struct program_params *pp, const char *lv_name,
{
return get_device_tier(pp, lv_name, e->dev);
}
+
+off_t
+get_avaiable_space(struct program_params *pp, const char *lv_name, int tier)
+{
+
+ const char *pv_name = get_tier_device(pp, lv_name, tier);
+ assert(pv_name);
+
+ off_t avaiable_space = get_max_space_tier(pp, lv_name, tier);
+
+ if (avaiable_space <= 0)
+ return avaiable_space;
+
+ long int used_space = get_used_space_on_pv(
+ get_volume_lv(pp, lv_name),
+ get_volume_vg(pp, lv_name),
+ pv_name);
+
+ used_space *= get_pe_size(get_volume_vg(pp, lv_name));
+
+ if (used_space > avaiable_space)
+ return 0;
+
+ return avaiable_space - used_space;
+}
View
@@ -78,4 +78,12 @@ void truncate_extents(struct extents *e, size_t len);
int get_extent_tier(struct program_params *pp, const char *lv_name,
struct extent *e);
+/**
+ * Returns amount of free space left that we can use on provided tier
+ *
+ * Space left is equal to maxUsedSpace - already used space
+ */
+off_t get_avaiable_space(struct program_params *pp, const char *lv_name,
+ int tier);
+
#endif
View
@@ -371,7 +371,7 @@ void parse_vgs_pe_size(int level, const char *file, int line,
}
// return size of extents in provided volume group
-uint64_t get_pe_size(char *vg_name)
+uint64_t get_pe_size(const char *vg_name)
{
for(size_t i=0; i<vg_pe_sizes_len; i++)
if (!strcmp(vg_pe_sizes[i].vg_name, vg_name))
@@ -439,7 +439,7 @@ void init_le_to_pe(struct program_params *pp)
// return number of free extents in PV in specified volume group
// or in whole volume group if pv_name is NULL
-uint64_t get_free_extent_number(char *vg_name, char *pv_name)
+uint64_t get_free_extent_number(const char *vg_name, const char *pv_name)
{
if (!vg_name)
return 0;
@@ -463,7 +463,8 @@ uint64_t get_free_extent_number(char *vg_name, char *pv_name)
}
// return used number of extents by LV on provided PV
-uint64_t get_used_space_on_pv(char *vg_name, char *lv_name, char *pv_name)
+uint64_t get_used_space_on_pv(const char *vg_name, const char *lv_name,
+ const char *pv_name)
{
assert(vg_name);
assert(lv_name);
View
@@ -36,17 +36,18 @@ void pv_info_free(struct pv_info *pv);
// on specific device
struct pv_info *LE_to_PE(char *vg_name, char *lv_name, uint64_t le_num);
-uint64_t get_pe_size(char *vg_name);
+uint64_t get_pe_size(const char *vg_name);
/**
* Returns amount of free extents on pv in vg
*/
-uint64_t get_free_extent_number(char *vg_name, char *pv_name);
+uint64_t get_free_extent_number(const char *vg_name, const char *pv_name);
/**
* Returns number of extents used by lv on specified pv in vg
*/
-uint64_t get_used_space_on_pv(char *vg_name, char *lv_name, char *pv_name);
+uint64_t get_used_space_on_pv(const char *vg_name, const char *lv_name,
+ const char *pv_name);
#endif /* ifndef _lvmls_h */
View
@@ -128,16 +128,6 @@ queue_extents_move(struct extents *ext, struct program_params *pp,
return 0;
}
-// TODO stub
-static off_t
-get_avaiable_space(struct program_params *pp, const char *lv_name, int tier)
-{
- if (tier <= 2)
- return 4 * 1024 * 1024 * 200;
-
- return 0;
-}
-
/**
* Add scores used for pinning extents to their current tier (so that they
* aren't moved back and forth because of small changes in score)

0 comments on commit 9654351

Please sign in to comment.