/** * mem_remove * * @return 0 on success, !0 otherwise */ static int mem_remove(void) { struct lmb_list_head *lmb_list; struct dr_node *lmb; unsigned int removable = 0; int rc = 0; lmb_list = get_lmbs(LMB_RANDOM_SORT); if (lmb_list == NULL) { say(ERROR, "Could not gather LMB (logical memory block " "information.\n"); return -1; } /* Can not know which lmbs are removable by the is_removable field * if AMS ballooning is active. */ if (!ams_balloon_active()) { /* Make sure we have enough removable memory to fulfill * this request */ for (lmb = lmb_list->lmbs; lmb; lmb = lmb->next) { if (lmb->is_removable) removable++; } if (removable == 0) { say(ERROR, "There is not enough removable memory " "available to fulfill the request.\n"); rc = -1; } if (removable < usr_drc_count) { say(INFO, "Only %u LMBs are currently candidates " "for removal.\n", removable); usr_drc_count = removable; } } if (!rc) { say(DEBUG, "Attempting removal of %d LMBs\n", usr_drc_count); rc = remove_lmbs(lmb_list); } say(ERROR, "Removed %d of %d requested LMB(s)\n", lmb_list->lmbs_modified, usr_drc_count); if (lmb_list->lmbs_modified < usr_drc_count) say(ERROR, "Unable to hotplug remove the remaining %d LMB(s)\n", usr_drc_count - lmb_list->lmbs_modified); report_resource_count(lmb_list->lmbs_modified); free_lmbs(lmb_list); return rc; }
int lsslot_chrp_mem(struct cmd_opts *opts) { struct lmb_list_head *lmb_list; struct dr_node *lmb; struct mem_scn *scn; int scn_offset = strlen("/sys/devices/system/memory/memory"); int lmb_offset = strlen(OFDT_BASE); lmb_list = get_lmbs(LMB_NORMAL_SORT); if (lmb_list == NULL || lmb_list->lmbs == NULL) return -1; if (lmb_list->drconf_buf) { print_drconf_mem(opts, lmb_list); } else { printf("lmb size: 0x%x\n", lmb_list->lmbs->lmb_size); printf("%-20s %-5s %c %s\n", "Memory Node", "Name", 'R', "Sections"); printf("%-20s %-5s %c %s\n", "-----------", "----", '-', "--------"); for (lmb = lmb_list->lmbs; lmb; lmb = lmb->next) { int first = 1; if (!lmb->is_owned) continue; if (!lmb_list->drconf_buf) printf("%-20s ", &lmb->ofdt_path[lmb_offset]); printf("%-5s %c ", lmb->drc_name, lmb->is_removable ? 'Y' : 'N'); for (scn = lmb->lmb_mem_scns; scn; scn = scn->next) { if (first) { printf(" %s", &scn->sysfs_path[scn_offset]); first = 0; } else printf(", %s", &scn->sysfs_path[scn_offset]); } printf("\n"); } } free_lmbs(lmb_list); return 0; }
/** * mem_add * @brief Add memory to the partition * * @returns 0 on success, !0 otherwise */ static int mem_add(void) { struct lmb_list_head *lmb_list; int rc; lmb_list = get_lmbs(LMB_NORMAL_SORT); if (lmb_list == NULL) { say(ERROR, "Could not gather LMB (logical memory block " "information.\n"); return -1; } say(DEBUG, "Attempting to add %d LMBs\n", usr_drc_count); rc = add_lmbs(lmb_list); say(DEBUG, "Added %d of %d requested LMB(s)\n", lmb_list->lmbs_modified, usr_drc_count); report_resource_count(lmb_list->lmbs_modified); free_lmbs(lmb_list); return rc; }