Example #1
0
/*
 * Run the Remove Device Group dialog
 */
void remDevGrpDialog(CDKSCREEN *main_cdk_screen) {
    char dev_grp_name[MAX_SYSFS_ATTR_SIZE] = {0},
    attr_path[MAX_SYSFS_PATH_SIZE] = {0},
    attr_value[MAX_SYSFS_ATTR_SIZE] = {0};
    char *error_msg = NULL, *confirm_msg = NULL;
    boolean confirm = FALSE;
    int temp_int = 0;

    /* Have the user choose a SCST device group */
    getSCSTDevGrpChoice(main_cdk_screen, dev_grp_name);
    if (dev_grp_name[0] == '\0')
        return;

    /* Get a final confirmation from user before we delete */
    SAFE_ASPRINTF(&confirm_msg,
            "Are you sure you want to delete SCST device group '%s?'",
            dev_grp_name);
    confirm = confirmDialog(main_cdk_screen, confirm_msg, NULL);
    FREE_NULL(confirm_msg);
    if (confirm) {
        /* Delete the specified SCST device group */
        snprintf(attr_path, MAX_SYSFS_PATH_SIZE,
                "%s/device_groups/mgmt", SYSFS_SCST_TGT);
        snprintf(attr_value, MAX_SYSFS_ATTR_SIZE, "del %s", dev_grp_name);
        if ((temp_int = writeAttribute(attr_path, attr_value)) != 0) {
            SAFE_ASPRINTF(&error_msg, "Couldn't delete SCST (ALUA) device group: %s",
                    strerror(temp_int));
            errorDialog(main_cdk_screen, error_msg, NULL);
            FREE_NULL(error_msg);
        }
    }

    /* Done */
    return;
}
Example #2
0
/*
 * Get MegaRAID logical drive information.
 */
MRLDRIVE *getMRLogicalDrive(int adapter_id, int ldrive_id) {
    MRLDRIVE *logical_drive = 0;
    FILE *megacli = NULL;
    char *command = NULL, *strtok_result = NULL;
    char line[MAX_MC_LINE] = {0};
    int status = 0;

    logical_drive = (MRLDRIVE *) calloc(1, sizeof(MRLDRIVE));
    if (logical_drive != NULL) {
        logical_drive->adapter_id = adapter_id;
        logical_drive->ldrive_id = ldrive_id;

        /* MegaCLI command */
        SAFE_ASPRINTF(&command, "%s -LDInfo -L%d -a%d -NoLog 2>&1",
                      MEGACLI_BIN, ldrive_id, adapter_id);
        megacli = popen(command, "r");

        /* Loop over command output */
        while (fgets(line, sizeof(line), megacli) != NULL) {
            if (strstr(line, "RAID Level          :")) {
                strtok_result = strtok(line, ":");
                strtok_result = strtok(NULL, ":");
                strncpy(logical_drive->raid_lvl, strStrip(strtok_result),
                        MAX_MR_ATTR_SIZE);

            } else if (strstr(line, "Size                :")) {
                strtok_result = strtok(line, ":");
                strtok_result = strtok(NULL, ":");
                strncpy(logical_drive->size, strStrip(strtok_result),
                        MAX_MR_ATTR_SIZE);

            } else if (strstr(line, "State               :")) {
                strtok_result = strtok(line, ":");
                strtok_result = strtok(NULL, ":");
                strncpy(logical_drive->state, strStrip(strtok_result),
                        MAX_MR_ATTR_SIZE);

            } else if (strstr(line, "Strip Size          :")) {
                strtok_result = strtok(line, ":");
                strtok_result = strtok(NULL, ":");
                strncpy(logical_drive->strip_size, strStrip(strtok_result),
                        MAX_MR_ATTR_SIZE);

            } else if (strstr(line, "Number Of Drives    :")) {
                sscanf(line, "%*s %*s %*s %*s %d", &logical_drive->drive_cnt);
            }
        }

        /* Done with MegaCLI */
        status = pclose(megacli);
        FREE_NULL(command);
        if (status != 0) {
            FREE_NULL(logical_drive);
            return NULL;
        }
    }

    /* Done */
    return logical_drive;
}
Example #3
0
bool InitialiseMidi()
{
  try
  {
    gMidiIn = new RtMidiIn();
  }
  catch ( RtError &error )
  {
    FREE_NULL(gMidiIn);
    error.printMessage();
    return false;
  }

  try
  {
    gMidiOut = new RtMidiOut();
  }
  catch ( RtError &error )
  {
    FREE_NULL(gMidiOut);
    error.printMessage();
    return false;
  }

  gMidiIn->setCallback( &MIDICallback );
  gMidiIn->ignoreTypes( !ENABLE_SYSEX, !ENABLE_MIDICLOCK, !ENABLE_ACTIVE_SENSING );

  return true;
}
Example #4
0
/*
 * Add MegaRAID logical drive.
 */
int addMRLogicalDrive(MRLDPROPS *ld_props, int num_disks, MRDISK *disks[],
                      char raid_lvl[], char strip_size[]) {
    char *command = NULL, *temp_pstr = NULL;
    int status = 0, i = 0, ret_val = 0, pd_val_size = 0, pd_line_size = 0;
    char pd_list_line_buffer[MAX_MR_PD_LIST_BUFF] = {0};

    /* Build the new LD command */
    for (i = 0; i < num_disks; i++) {
        if (i == (num_disks - 1))
            SAFE_ASPRINTF(&temp_pstr, "%d:%d", disks[i]->enclosure_id,
                          disks[i]->slot_num);
        else
            SAFE_ASPRINTF(&temp_pstr, "%d:%d,", disks[i]->enclosure_id,
                          disks[i]->slot_num);
        /* We add one extra for the null byte */
        pd_val_size = strlen(temp_pstr) + 1;
        pd_line_size = pd_line_size + pd_val_size;
        if (pd_line_size >= MAX_MR_PD_LIST_BUFF) {
            FREE_NULL(temp_pstr);
            return -1;
        } else {
            strcat(pd_list_line_buffer, temp_pstr);
            FREE_NULL(temp_pstr);
        }
    }
    SAFE_ASPRINTF(&command, "%s -CfgLdAdd -r%s[%s] %s %s %s %s -strpsz%s -a%d "
                  "-Silent -NoLog > /dev/null 2>&1",
                  MEGACLI_BIN, raid_lvl, pd_list_line_buffer, ld_props->write_policy,
                  ld_props->read_policy, ld_props->cache_policy,
                  ld_props->bbu_cache_policy, strip_size, ld_props->adapter_id);

    /* Execute the command and check exit */
    status = system(command);
    if (status == -1) {
        ret_val = -1;
    } else {
        if (WIFEXITED(status)) {
            if (WEXITSTATUS(status) == 254) {
                /* MegaCLI gives a exit status of 254 when using CfgLdAdd
                 * and it successfully created the volume; it gives
                 * an error about 'proc_add_new_ld: scandir failed' */
                ret_val = 0;
            } else {
                ret_val = WEXITSTATUS(status);
            }
        } else {
            ret_val = -1;
        }
    }

    /* Done */
    FREE_NULL(command);
    return ret_val;
}
Example #5
0
/*
 * Run the Remove Target from Group dialog
 */
void remTgtFromGrpDialog(CDKSCREEN *main_cdk_screen) {
    char dev_grp_name[MAX_SYSFS_ATTR_SIZE] = {0},
    tgt_grp_name[MAX_SYSFS_ATTR_SIZE] = {0},
    target_name[MAX_SYSFS_ATTR_SIZE] = {0},
    attr_path[MAX_SYSFS_PATH_SIZE] = {0},
    attr_value[MAX_SYSFS_ATTR_SIZE] = {0};
    char *error_msg = NULL, *confirm_msg = NULL;
    boolean confirm = FALSE;
    int temp_int = 0;

    /* Have the user choose a SCST device group */
    getSCSTDevGrpChoice(main_cdk_screen, dev_grp_name);
    if (dev_grp_name[0] == '\0')
        return;

    /* Get target group choice from user (based on previously
     * selected device group) */
    getSCSTTgtGrpChoice(main_cdk_screen, dev_grp_name, tgt_grp_name);
    if (tgt_grp_name[0] == '\0')
        return;

    /* Get target group choice from user (based on previously
     * selected device group) */
    getSCSTTgtGrpTgtChoice(main_cdk_screen, dev_grp_name, tgt_grp_name,
            target_name);
    if (target_name[0] == '\0')
        return;

    /* Get a final confirmation from user before we delete */
    SAFE_ASPRINTF(&confirm_msg, "target '%s' from group '%s?'",
            target_name, tgt_grp_name);
    confirm = confirmDialog(main_cdk_screen,
            "Are you sure you want to remove SCST", confirm_msg);
    FREE_NULL(confirm_msg);
    if (confirm) {
        /* Remove the SCST target from the target group (ALUA) */
        snprintf(attr_path, MAX_SYSFS_PATH_SIZE,
                "%s/device_groups/%s/target_groups/%s/mgmt",
                SYSFS_SCST_TGT, dev_grp_name, tgt_grp_name);
        snprintf(attr_value, MAX_SYSFS_ATTR_SIZE, "del %s", target_name);
        if ((temp_int = writeAttribute(attr_path, attr_value)) != 0) {
            SAFE_ASPRINTF(&error_msg,
                    "Couldn't delete SCST (ALUA) target from target group: %s",
                    strerror(temp_int));
            errorDialog(main_cdk_screen, error_msg, NULL);
            FREE_NULL(error_msg);
        }
    }

    /* Done */
    return;
}
Example #6
0
/*
 * Get enclosure/slot information for given logical drive ID.
 */
int getMRLDDisks(int adapter_id, int ldrive_id, int encl_ids[], int slots[]) {
    FILE *megacli = NULL;
    char *command = NULL, *strtok_result = NULL, *vdrive_line = NULL;
    char line[MAX_MC_LINE] = {0};
    boolean ld_start = FALSE;
    int status = 0, ld_drv_cnt = 0, encl_count = 0, slot_count = 0;

    /* MegaCLI command */
    SAFE_ASPRINTF(&command, "%s -LdPdInfo -a%d -NoLog 2>&1",
                  MEGACLI_BIN, adapter_id);
    megacli = popen(command, "r");

    /* Loop until LD is found -- then count PDs (and get data) */
    SAFE_ASPRINTF(&vdrive_line, "Virtual Drive: %d", ldrive_id);
    while (fgets(line, sizeof (line), megacli) != NULL) {
        if ((ld_start == FALSE) && (strstr(line, vdrive_line) != NULL)) {
            ld_start = TRUE;
            FREE_NULL(vdrive_line);
            vdrive_line = NULL;

        } else if (ld_start && strstr(line, "Number Of Drives    :") &&
                   ld_drv_cnt == 0) {
            strtok_result = strtok(line, ":");
            strtok_result = strtok(NULL, ":");
            sscanf(strtok_result, " %d", &ld_drv_cnt);

        } else if (ld_start && strstr(line, "Enclosure Device ID:") &&
                   encl_count < ld_drv_cnt) {
            strtok_result = strtok(line, ":");
            strtok_result = strtok(NULL, ":");
            sscanf(strtok_result, " %d", &encl_ids[encl_count]);
            encl_count++;

        } else if (ld_start && strstr(line, "Slot Number:") &&
                   slot_count < ld_drv_cnt) {
            strtok_result = strtok(line, ":");
            strtok_result = strtok(NULL, ":");
            sscanf(strtok_result, " %d", &slots[slot_count]);
            slot_count++;
        }
    }

    /* Done with MegaCLI */
    status = pclose(megacli);
    FREE_NULL(command);
    if (status != 0) {
        return -1;
    }

    /* Done */
    return ld_drv_cnt;
}
Example #7
0
/*
 * Get a count of the enclosures for the specified adapter.
 */
int getMREnclCount(int adapter_id) {
    FILE *megacli = NULL;
    char *command = NULL, *strtok_result = NULL;
    int status = 0, count = 0;
    char line[MAX_MC_LINE] = {0};

    /* MegaCLI command */
    SAFE_ASPRINTF(&command, "%s -EncInfo -a%d -NoLog 2>&1", MEGACLI_BIN, adapter_id);
    megacli = popen(command, "r");

    /* Loop over command output */
    while (fgets(line, sizeof(line), megacli) != NULL) {
        if (strstr(line, "    Number of enclosures on adapter")) {
            strtok_result = strtok(line, "--");
            strtok_result = strtok(NULL, "--");
            sscanf(strtok_result, " %d", &count);
        }
    }

    /* Done with MegaCLI */
    status = pclose(megacli);
    FREE_NULL(command);
    if (status != 0) {
        return -1;
    }

    /* Done */
    return count;
}
Example #8
0
/*
 * Get number of adapters (RAID controllers).
 */
int getMRAdapterCount() {
    FILE *megacli = NULL;
    char *command = NULL, *mc_version = NULL;
    int count = 0;
    char line[MAX_MC_LINE] = {0};

    /* A cheezy check to see if MegaCLI is "working" -- see comments below */
    mc_version = getMegaCLIVersion();
    if (!mc_version) {
        return -1;
    }

    /* MegaCLI command */
    SAFE_ASPRINTF(&command, "%s -adpCount -NoLog 2>&1", MEGACLI_BIN);
    megacli = popen(command, "r");

    /* Loop over command output */
    while (fgets(line, sizeof (line), megacli) != NULL) {
        if (strstr(line, "Controller Count:"))
            sscanf(line, "%*s %*s %d", &count);
    }

    /* For this one we ignore the exit code -- when using the 'adpCount' option
     * with MegaCLI, it also returns the adapter count as the exit code */
    pclose(megacli);

    /* Done */
    FREE_NULL(command);
    return count;
}
Example #9
0
/*
 * Get count of MegaRAID logical (virtual) drives for given adapter.
 */
int getMRLDCount(int adapter_id) {
    FILE *megacli = NULL;
    char *command = NULL, *strtok_result = NULL, *mc_version = NULL;
    int count = 0;
    char line[MAX_MC_LINE] = {0};

    /* A cheezy check to see if MegaCLI is "working" -- see comments below */
    mc_version = getMegaCLIVersion();
    if (!mc_version) {
        return -1;
    }

    /* MegaCLI command */
    SAFE_ASPRINTF(&command, "%s -LDGetNum -a%d -NoLog 2>&1",
                  MEGACLI_BIN, adapter_id);
    megacli = popen(command, "r");

    /* Loop over command output */
    while (fgets(line, sizeof(line), megacli) != NULL) {
        if (strstr(line, "Number of Virtual Drives Configured on Adapter")) {
            strtok_result = strtok(line, ":");
            strtok_result = strtok(NULL, ":");
            sscanf(strtok_result, " %d", &count);
        }
    }

    /* For this one we ignore the exit code -- when using the 'LDGetNum' option
     * with MegaCLI, it also returns the LD count as the exit code */
    pclose(megacli);

    /* Done */
    FREE_NULL(command);
    return count;
}
Example #10
0
/*
 * Run the Add Device to Group dialog
 */
void addDevToGrpDialog(CDKSCREEN *main_cdk_screen) {
    char device_name[MAX_SYSFS_ATTR_SIZE] = {0},
    dev_handler[MAX_SYSFS_ATTR_SIZE] = {0},
    dev_grp_name[MAX_SYSFS_ATTR_SIZE] = {0},
    attr_path[MAX_SYSFS_PATH_SIZE] = {0},
    attr_value[MAX_SYSFS_ATTR_SIZE] = {0};
    char *error_msg = NULL;
    int temp_int = 0;

    /* Have the user choose a SCST device */
    getSCSTDevChoice(main_cdk_screen, device_name, dev_handler);
    if (device_name[0] == '\0')
        return;

    /* Have the user choose a SCST device group (to add the device to) */
    getSCSTDevGrpChoice(main_cdk_screen, dev_grp_name);
    if (dev_grp_name[0] == '\0')
        return;

    /* Add the SCST device to the device group (ALUA) */
    snprintf(attr_path, MAX_SYSFS_PATH_SIZE,
            "%s/device_groups/%s/devices/mgmt",
            SYSFS_SCST_TGT, dev_grp_name);
    snprintf(attr_value, MAX_SYSFS_ATTR_SIZE, "add %s", device_name);
    if ((temp_int = writeAttribute(attr_path, attr_value)) != 0) {
        SAFE_ASPRINTF(&error_msg,
                "Couldn't add SCST (ALUA) device to device group: %s",
                strerror(temp_int));
        errorDialog(main_cdk_screen, error_msg, NULL);
        FREE_NULL(error_msg);
    }

    /* Done */
    return;
}
Example #11
0
/*
 * Get MegaCLI version -- just the actual number for now.
 */
char *getMegaCLIVersion() {
    FILE *megacli = NULL;
    char *command = NULL, *version_p = NULL;
    int status = 0;
    char line[MAX_MC_LINE] = {0}, version[20] = {0};

    /* MegaCLI command */
    SAFE_ASPRINTF(&command, "%s -help -NoLog 2>&1", MEGACLI_BIN);
    megacli = popen(command, "r");

    /* Loop over command output */
    while (fgets(line, sizeof (line), megacli) != NULL) {
        if (strstr(line, "MegaCLI SAS RAID Management Tool  Ver")) {
            sscanf(line, "%*s %*s %*s %*s %*s %*s %s", version);
        }
    }

    status = pclose(megacli);
    FREE_NULL(command);
    if (status != 0) {
        return NULL;
    }

    /* Done */
    version_p = version;
    return version_p;
}
Example #12
0
/*
 * Run the Add Device Group dialog
 */
void addDevGrpDialog(CDKSCREEN *main_cdk_screen) {
    CDKENTRY *dev_grp_name_entry = 0;
    char attr_path[MAX_SYSFS_PATH_SIZE] = {0},
            attr_value[MAX_SYSFS_ATTR_SIZE] = {0};
    char *dev_grp_name = NULL, *error_msg = NULL;
    int temp_int = 0;

    while (1) {
        /* Get new device group name (entry widget) */
        dev_grp_name_entry = newCDKEntry(main_cdk_screen, CENTER, CENTER,
                "<C></31/B>Add New Device Group\n",
                "</B>New Group Name (no spaces): ",
                COLOR_DIALOG_SELECT, '_' | COLOR_DIALOG_INPUT, vMIXED,
                SCST_DEV_GRP_NAME_LEN, 0, SCST_DEV_GRP_NAME_LEN, TRUE, FALSE);
        if (!dev_grp_name_entry) {
            errorDialog(main_cdk_screen, ENTRY_ERR_MSG, NULL);
            break;
        }
        setCDKEntryBoxAttribute(dev_grp_name_entry, COLOR_DIALOG_BOX);
        setCDKEntryBackgroundAttrib(dev_grp_name_entry, COLOR_DIALOG_TEXT);

        /* Draw the entry widget */
        curs_set(1);
        dev_grp_name = activateCDKEntry(dev_grp_name_entry, 0);

        /* Check exit from widget */
        if (dev_grp_name_entry->exitType == vNORMAL) {
            /* Check group name for bad characters */
            if (!checkInputStr(main_cdk_screen, NAME_CHARS, dev_grp_name))
                break;

            /* Add the new device group */
            snprintf(attr_path, MAX_SYSFS_PATH_SIZE,
                    "%s/device_groups/mgmt", SYSFS_SCST_TGT);
            snprintf(attr_value, MAX_SYSFS_ATTR_SIZE,
                    "create %s", dev_grp_name);
            if ((temp_int = writeAttribute(attr_path, attr_value)) != 0) {
                SAFE_ASPRINTF(&error_msg,
                        "Couldn't add SCST (ALUA) device group: %s",
                        strerror(temp_int));
                errorDialog(main_cdk_screen, error_msg, NULL);
                FREE_NULL(error_msg);
            }
        }
        break;
    }

    /* Done */
    destroyCDKEntry(dev_grp_name_entry);
    return;
}
Example #13
0
sem_t* sem_crear(int* shmid, key_t* shmkey, int contador_ftok){
	sem_t* sem= NULL;
	//pid_t pid; /*      fork pid                */
	//unsigned int n; /*      fork count              */
	unsigned int value; /*      semaphore value         */

	/* initialize a shared variable in shared memory */

	char* sem_name = string_from_format("pSem_%d", contador_ftok);

	//shmkey = ftok("/dev/null", 5); /* valid directory name and a number */
	*shmkey = ftok("/dev/null", contador_ftok); /* valid directory name and a number */

	//printf("shmkey for p = %d\n", *shmkey);
	*shmid = shmget(*shmkey, sizeof(int), 0644 | IPC_CREAT);
	if (*shmid < 0) { /* shared memory error check */
		perror("shmget\n");
		exit(1);
	}

	///////////////////////////////////////////
	value = 0;
	/* initialize semaphores for shared processes */
	//sem = sem_open("pSem", O_CREAT | O_EXCL, 0644, value);


	//sem = sem_open("pSem", O_CREAT , 0644, value);
	sem = sem_open(sem_name, O_CREAT , 0644, value);
	if(sem==SEM_FAILED){
		perror("sem_open___");
		printf("***************************************************sdfadfasd\n");
		_exit(1);
	}

	/* name of semaphore is "pSem", semaphore is reached using this name */
	//sem_unlink("pSem");
	sem_unlink(sem_name);
	/* unlink prevents the semaphore existing forever */
	/* if a crash occurs during the execution         */
	//printf ("semaphores initialized.\n\n");

	FREE_NULL(sem_name);

	return sem;
}
Example #14
0
/*
 * Get MegaRAID logical drive IDs.
 */
int getMRLDIDNums(int adapter_id, int ld_count, int ld_ids[]) {
    FILE *megacli = NULL;
    char *command = NULL;
    char line[MAX_MC_LINE] = {0};
    int status = 0, ld_line_cnt = 0, ret_val = 0;

    /* MegaCLI command */
    SAFE_ASPRINTF(&command, "%s -LDInfo -Lall -a%d -NoLog 2>&1",
                  MEGACLI_BIN, adapter_id);
    megacli = popen(command, "r");

    /* Loop over command output */
    ld_line_cnt = 0;
    while (fgets(line, sizeof (line), megacli) != NULL) {
        if (strstr(line, "Virtual Drive:")) {
            sscanf(line, "%*s %*s %d", &ld_ids[ld_line_cnt]);
            ld_line_cnt++;
        }
    }

    /* Done with MegaCLI */
    status = pclose(megacli);
    if (status == -1) {
        ret_val = -1;
    } else {
        if (WIFEXITED(status)) {
            ret_val = WEXITSTATUS(status);
        } else {
            ret_val = -1;
        }
    }

    /* Make sure we got the same number of IDs */
    if (ld_count != ld_line_cnt)
        ret_val = -1;

    /* Done */
    FREE_NULL(command);
    return ret_val;
}
Example #15
0
/*
 * Delete MegaRAID logical drive.
 */
int delMRLogicalDrive(int adapter_id, int ldrive_id) {
    char *command = NULL;
    int status = 0, ret_val = 0;

    /* The delete-logical-drive command */
    SAFE_ASPRINTF(&command, "%s -CfgLdDel -L%d -a%d -Silent -NoLog > /dev/null 2>&1",
                  MEGACLI_BIN, ldrive_id, adapter_id);

    /* Execute the command and check exit */
    status = system(command);
    if (status == -1) {
        ret_val = -1;
    } else {
        if (WIFEXITED(status)) {
            ret_val = WEXITSTATUS(status);
        } else {
            ret_val = -1;
        }
    }

    /* Done */
    FREE_NULL(command);
    return ret_val;
}
Example #16
0
/*
 * Set adapter properties via MegaCLI.
 */
int setMRAdapterProps(MRADPPROPS *adp_props) {
    char *command = NULL;
    int status = 0;

    /* Set CacheFlushInterval */
    SAFE_ASPRINTF(&command, "%s -AdpSetProp CacheFlushInterval -%d -a%d "
                  "-Silent -NoLog > /dev/null 2>&1", MEGACLI_BIN,
                  adp_props->cache_flush, adp_props->adapter_id);
    status = system(command);
    FREE_NULL(command);
    if (status == -1) {
        return -1;
    } else {
        if (WIFEXITED(status)) {
            if (WEXITSTATUS(status) != 0)
                return WEXITSTATUS(status);
        } else {
            return -1;
        }
    }

    /* Set RebuildRate */
    SAFE_ASPRINTF(&command, "%s -AdpSetProp RebuildRate -%d -a%d "
                  "-Silent -NoLog > /dev/null 2>&1", MEGACLI_BIN,
                  adp_props->rebuild_rate, adp_props->adapter_id);
    status = system(command);
    FREE_NULL(command);
    if (status == -1) {
        return -1;
    } else {
        if (WIFEXITED(status)) {
            if (WEXITSTATUS(status) != 0)
                return WEXITSTATUS(status);
        } else {
            return -1;
        }
    }

    /* Set ClusterEnable */
    SAFE_ASPRINTF(&command, "%s -AdpSetProp ClusterEnable -%d -a%d "
                  "-Silent -NoLog > /dev/null 2>&1", MEGACLI_BIN,
                  (int) adp_props->cluster, adp_props->adapter_id);
    status = system(command);
    FREE_NULL(command);
    if (status == -1) {
        return -1;
    } else {
        if (WIFEXITED(status)) {
            if (WEXITSTATUS(status) != 0)
                return WEXITSTATUS(status);
        } else {
            return -1;
        }
    }

    /* Set NCQEnbl/NCQDsbl */
    if (adp_props->ncq == TRUE)
        SAFE_ASPRINTF(&command, "%s -AdpSetProp NCQEnbl -a%d "
                      "-Silent -NoLog > /dev/null 2>&1", MEGACLI_BIN,
                      adp_props->adapter_id);
    else
        SAFE_ASPRINTF(&command, "%s -AdpSetProp NCQDsbl -a%d "
                      "-Silent -NoLog > /dev/null 2>&1", MEGACLI_BIN,
                      adp_props->adapter_id);
    status = system(command);
    FREE_NULL(command);
    if (status == -1) {
        return -1;
    } else {
        if (WIFEXITED(status)) {
            if (WEXITSTATUS(status) != 0)
                return WEXITSTATUS(status);
        } else {
            return -1;
        }
    }

    /* Done */
    return 0;
}
Example #17
0
/*
 * Get adapter attributes from MegaCLI.
 */
MRADAPTER *getMRAdapter(int adapter_id) {
    MRADAPTER *adapter = 0;
    FILE *megacli = NULL;
    char *command = NULL, *strtok_result = NULL;
    char line[MAX_MC_LINE] = {0};
    int status = 0;

    adapter = (MRADAPTER *) calloc(1, sizeof(MRADAPTER));
    if (adapter != NULL) {
        adapter->adapter_id = adapter_id;

        /* MegaCLI command */
        SAFE_ASPRINTF(&command, "%s -AdpAllInfo -a%d -NoLog 2>&1",
                      MEGACLI_BIN, adapter_id);
        megacli = popen(command, "r");

        /* Loop over command output */
        while (fgets(line, sizeof(line), megacli) != NULL) {
            if (strstr(line, "Product Name    :")) {
                strtok_result = strtok(line, ":");
                strtok_result = strtok(NULL, ":");
                strncpy(adapter->prod_name, strStrip(strtok_result),
                        MAX_MR_ATTR_SIZE);

            } else if (strstr(line, "Serial No       :")) {
                strtok_result = strtok(line, ":");
                strtok_result = strtok(NULL, ":");
                strncpy(adapter->serial, strStrip(strtok_result),
                        MAX_MR_ATTR_SIZE);

            } else if (strstr(line, "FW Package Build:")) {
                strtok_result = strtok(line, ":");
                strtok_result = strtok(NULL, ":");
                strncpy(adapter->firmware, strStrip(strtok_result),
                        MAX_MR_ATTR_SIZE);

            } else if (strstr(line, "BBU              :")) {
                strtok_result = strtok(line, ":");
                strtok_result = strtok(NULL, ":");
                strncpy(adapter->bbu, strStrip(strtok_result),
                        MAX_MR_ATTR_SIZE);

            } else if (strstr(line, "Memory Size      :")) {
                strtok_result = strtok(line, ":");
                strtok_result = strtok(NULL, ":");
                strncpy(adapter->memory, strStrip(strtok_result),
                        MAX_MR_ATTR_SIZE);

            } else if (strstr(line, "Host Interface  :")) {
                strtok_result = strtok(line, ":");
                strtok_result = strtok(NULL, ":");
                strncpy(adapter->interface, strStrip(strtok_result),
                        MAX_MR_ATTR_SIZE);

            } else if (strstr(line, "Virtual Drives    :")) {
                sscanf(line, "%*s %*s %*s %d", &adapter->logical_drv_cnt);

            } else if (strstr(line, "  Disks           :")) {
                sscanf(line, "%*s %*s %d", &adapter->disk_cnt);

            } else if (strstr(line, "Cluster Permitted     :")) {
                strtok_result = strtok(line, ":");
                strtok_result = strtok(NULL, ":");
                strncpy(adapter->cluster, strStrip(strtok_result),
                        MAX_MR_ATTR_SIZE);

            } else if (strstr(line, "Cluster Active        :")) {
                strtok_result = strtok(line, ":");
                strtok_result = strtok(NULL, ":");
                strncpy(adapter->cluster_on, strStrip(strtok_result),
                        MAX_MR_ATTR_SIZE);
            }
        }

        /* Done with MegaCLI */
        status = pclose(megacli);
        FREE_NULL(command);
        if (status != 0) {
            FREE_NULL(adapter);
            return NULL;
        }
    }

    /* Done */
    return adapter;
}
Example #18
0
/*
 * Set logical drive properties.
 */
int setMRLDProps(MRLDPROPS *ld_props) {
    char *command = NULL;
    int status = 0;

    /* Set cache policy */
    SAFE_ASPRINTF(&command, "%s -LDSetProp %s -L%d -a%d "
                  "-Silent -NoLog > /dev/null 2>&1", MEGACLI_BIN,
                  ld_props->cache_policy, ld_props->ldrive_id, ld_props->adapter_id);
    status = system(command);
    FREE_NULL(command);
    if (status == -1) {
        return -1;
    } else {
        if (WIFEXITED(status)) {
            if (WEXITSTATUS(status) != 0)
                return WEXITSTATUS(status);
        } else {
            return -1;
        }
    }

    /* Set write-cache policy */
    SAFE_ASPRINTF(&command, "%s -LDSetProp %s -L%d -a%d "
                  "-Silent -NoLog > /dev/null 2>&1", MEGACLI_BIN,
                  ld_props->write_policy, ld_props->ldrive_id, ld_props->adapter_id);
    status = system(command);
    FREE_NULL(command);
    if (status == -1) {
        return -1;
    } else {
        if (WIFEXITED(status)) {
            if (WEXITSTATUS(status) != 0)
                return WEXITSTATUS(status);
        } else {
            return -1;
        }
    }

    /* Set read-cache policy */
    SAFE_ASPRINTF(&command, "%s -LDSetProp %s -L%d -a%d "
                  "-Silent -NoLog > /dev/null 2>&1", MEGACLI_BIN,
                  ld_props->read_policy, ld_props->ldrive_id, ld_props->adapter_id);
    status = system(command);
    FREE_NULL(command);
    if (status == -1) {
        return -1;
    } else {
        if (WIFEXITED(status)) {
            if (WEXITSTATUS(status) != 0)
                return WEXITSTATUS(status);
        } else {
            return -1;
        }
    }

    /* Set BBU cache policy */
    SAFE_ASPRINTF(&command, "%s -LDSetProp %s -L%d -a%d "
                  "-Silent -NoLog > /dev/null 2>&1", MEGACLI_BIN,
                  ld_props->bbu_cache_policy, ld_props->ldrive_id,
                  ld_props->adapter_id);
    status = system(command);
    FREE_NULL(command);
    if (status == -1) {
        return -1;
    } else {
        if (WIFEXITED(status)) {
            if (WEXITSTATUS(status) != 0)
                return WEXITSTATUS(status);
        } else {
            return -1;
        }
    }

    /* Set LD name (if not empty) */
    if (strlen(ld_props->name) != 0) {
        SAFE_ASPRINTF(&command, "%s -LDSetProp -Name %s -L%d -a%d "
                      "-Silent -NoLog > /dev/null 2>&1", MEGACLI_BIN,
                      ld_props->name, ld_props->ldrive_id, ld_props->adapter_id);
        status = system(command);
        FREE_NULL(command);
        if (status == -1) {
            return -1;
        } else {
            if (WIFEXITED(status)) {
                if (WEXITSTATUS(status) != 0)
                    return WEXITSTATUS(status);
            } else {
                return -1;
            }
        }
    }

    /* Done */
    return 0;
}
Example #19
0
/*
 * Get MegaRAID logical (virtual) drive properties.
 */
MRLDPROPS *getMRLDProps(int adapter_id, int ldrive_id) {
    MRLDPROPS *ld_props = 0;
    FILE *megacli = NULL;
    char *command = NULL, *strtok_result = NULL;
    char line[MAX_MC_LINE] = {0}, temp_str[MAX_MC_LINE] = {0};
    int status = 0;

    ld_props = (MRLDPROPS *) calloc(1, sizeof(MRLDPROPS));
    if (ld_props != NULL) {
        ld_props->adapter_id = adapter_id;
        ld_props->ldrive_id = ldrive_id;

        /* Get cache policies */
        SAFE_ASPRINTF(&command, "%s -LDGetProp -Cache -L%d -a%d -NoLog 2>&1",
                      MEGACLI_BIN, ldrive_id, adapter_id);
        megacli = popen(command, "r");
        while (fgets(line, sizeof(line), megacli) != NULL) {
            if (strstr(line, "Cache Policy:")) {
                strtok_result = strtok(line, ":");
                strtok_result = strtok(NULL, ":");
                strtok_result = strtok(NULL, ":");
                strtok_result = strtok(NULL, ":");
                strcpy(temp_str, strtok_result);

                /* Write policy */
                strtok_result = strtok(temp_str, ",");
                if (strstr(strStrip(strtok_result), "WriteThrough")) {
                    strncpy(ld_props->write_policy, "WT", MAX_MR_ATTR_SIZE);
                } else if (strstr(strStrip(strtok_result), "WriteBack")) {
                    strncpy(ld_props->write_policy, "WB", MAX_MR_ATTR_SIZE);
                } else {
                    strncpy(ld_props->write_policy, "UNKNOWN",
                            MAX_MR_ATTR_SIZE);
                }

                /* Read policy */
                strtok_result = strtok(NULL, ",");
                if (strstr(strStrip(strtok_result), "ReadAheadNone")) {
                    strncpy(ld_props->read_policy, "NORA", MAX_MR_ATTR_SIZE);
                } else if (strstr(strStrip(strtok_result), "ReadAhead")) {
                    strncpy(ld_props->read_policy, "RA", MAX_MR_ATTR_SIZE);
                } else if (strstr(strStrip(strtok_result), "ReadAdaptive")) {
                    strncpy(ld_props->read_policy, "ADRA", MAX_MR_ATTR_SIZE);
                } else {
                    strncpy(ld_props->read_policy, "UNKNOWN",
                            MAX_MR_ATTR_SIZE);
                }

                /* Cache policy */
                strtok_result = strtok(NULL, ",");
                if (strstr(strStrip(strtok_result), "Direct")) {
                    strncpy(ld_props->cache_policy, "Direct", MAX_MR_ATTR_SIZE);
                } else if (strstr(strStrip(strtok_result), "Cached")) {
                    strncpy(ld_props->cache_policy, "Cached", MAX_MR_ATTR_SIZE);
                } else {
                    strncpy(ld_props->cache_policy, "UNKNOWN",
                            MAX_MR_ATTR_SIZE);
                }

                /* BBU cache policy */
                strtok_result = strtok(NULL, ",");
                if (strstr(strStrip(strtok_result),
                           "No Write Cache if bad BBU")) {
                    strncpy(ld_props->bbu_cache_policy, "NoCachedBadBBU",
                            MAX_MR_ATTR_SIZE);
                } else if (strstr(strStrip(strtok_result),
                                  "Write Cache OK if bad BBU")) {
                    strncpy(ld_props->bbu_cache_policy, "CachedBadBBU",
                            MAX_MR_ATTR_SIZE);
                } else {
                    strncpy(ld_props->bbu_cache_policy, "UNKNOWN",
                            MAX_MR_ATTR_SIZE);
                }
            }
        }
        status = pclose(megacli);
        FREE_NULL(command);
        if (status != 0) {
            return NULL;
        }

        /* Get Name */
        SAFE_ASPRINTF(&command, "%s -LDGetProp -Name -L%d -a%d -NoLog 2>&1",
                      MEGACLI_BIN, ldrive_id, adapter_id);
        megacli = popen(command, "r");
        while (fgets(line, sizeof(line), megacli) != NULL) {
            if (strstr(line, "Name:")) {
                strtok_result = strtok(line, ":");
                strtok_result = strtok(NULL, ":");
                strtok_result = strtok(NULL, ":");
                strtok_result = strtok(NULL, ":");
                strncpy(ld_props->name, strStrip(strtok_result),
                        MAX_MR_ATTR_SIZE);
            }
        }
        status = pclose(megacli);
        FREE_NULL(command);
        if (status != 0) {
            return NULL;
        }
    }

    /* Done */
    return ld_props;
}
Example #20
0
/*
 * Run the Device/Target Group Layout dialog
 */
void devTgtGrpLayoutDialog(CDKSCREEN *main_cdk_screen) {
    CDKSWINDOW *alua_info = 0;
    char *swindow_info[MAX_ALUA_LAYOUT_LINES] = {NULL};
    int i = 0, line_pos = 0;
    char dir_name[MAX_SYSFS_PATH_SIZE] = {0},
            tmp_buff[MAX_SYSFS_ATTR_SIZE] = {0};
    DIR *dev_grp_dir_stream = NULL, *tgt_grp_dir_stream = NULL,
            *tgt_dir_stream = NULL, *dev_dir_stream = NULL;
    struct dirent *dev_grp_dir_entry = NULL, *tgt_grp_dir_entry = NULL,
            *tgt_dir_entry = NULL, *dev_dir_entry = NULL;

    /* Setup scrolling window widget */
    alua_info = newCDKSwindow(main_cdk_screen, CENTER, CENTER,
            (ALUA_LAYOUT_ROWS + 2), (ALUA_LAYOUT_COLS + 2),
            "<C></31/B>SCST ALUA Device/Target Group Layout\n",
            MAX_ALUA_LAYOUT_LINES, TRUE, FALSE);
    if (!alua_info) {
        errorDialog(main_cdk_screen, SWINDOW_ERR_MSG, NULL);
        return;
    }
    setCDKSwindowBackgroundAttrib(alua_info, COLOR_DIALOG_TEXT);
    setCDKSwindowBoxAttribute(alua_info, COLOR_DIALOG_BOX);

    line_pos = 0;
    while (1) {
        /* We'll start with the SCST device groups */
        snprintf(dir_name, MAX_SYSFS_PATH_SIZE,
                "%s/device_groups", SYSFS_SCST_TGT);
        if ((dev_grp_dir_stream = opendir(dir_name)) == NULL) {
            if (line_pos < MAX_ALUA_LAYOUT_LINES) {
                SAFE_ASPRINTF(&swindow_info[line_pos], "opendir(): %s",
                        strerror(errno));
                line_pos++;
            }
            break;
        }
        while ((dev_grp_dir_entry = readdir(dev_grp_dir_stream)) != NULL) {
            /* The device group names are directories; skip '.' and '..' */
            if ((dev_grp_dir_entry->d_type == DT_DIR) &&
                    (strcmp(dev_grp_dir_entry->d_name, ".") != 0) &&
                    (strcmp(dev_grp_dir_entry->d_name, "..") != 0)) {
                if (line_pos < MAX_ALUA_LAYOUT_LINES) {
                    SAFE_ASPRINTF(&swindow_info[line_pos],
                            "</B>Device Group:<!B> %s",
                            dev_grp_dir_entry->d_name);
                    line_pos++;
                }

                /* Now get all of the device names for this device group */
                snprintf(dir_name, MAX_SYSFS_PATH_SIZE,
                        "%s/device_groups/%s/devices",
                        SYSFS_SCST_TGT, dev_grp_dir_entry->d_name);
                if ((dev_dir_stream = opendir(dir_name)) == NULL) {
                    if (line_pos < MAX_ALUA_LAYOUT_LINES) {
                        SAFE_ASPRINTF(&swindow_info[line_pos],
                                "opendir(): %s", strerror(errno));
                        line_pos++;
                    }
                    break;
                }
                while ((dev_dir_entry = readdir(dev_dir_stream)) != NULL) {
                    /* The device names are links */
                    if (dev_dir_entry->d_type == DT_LNK) {
                        if (line_pos < MAX_ALUA_LAYOUT_LINES) {
                            SAFE_ASPRINTF(&swindow_info[line_pos],
                                    "\t</B>Device:<!B> %s",
                                    dev_dir_entry->d_name);
                            line_pos++;
                        }
                    }
                }
                closedir(dev_dir_stream);

                /* Now get all of the target groups for this device group */
                snprintf(dir_name, MAX_SYSFS_PATH_SIZE,
                        "%s/device_groups/%s/target_groups", SYSFS_SCST_TGT,
                        dev_grp_dir_entry->d_name);
                if ((tgt_grp_dir_stream = opendir(dir_name)) == NULL) {
                    if (line_pos < MAX_ALUA_LAYOUT_LINES) {
                        SAFE_ASPRINTF(&swindow_info[line_pos], "opendir(): %s",
                                strerror(errno));
                        line_pos++;
                    }
                    break;
                }
                while ((tgt_grp_dir_entry = readdir(tgt_grp_dir_stream)) !=
                        NULL) {
                    /* The target group names are directories;
                     * skip '.' and '..' */
                    if ((tgt_grp_dir_entry->d_type == DT_DIR) &&
                            (strcmp(tgt_grp_dir_entry->d_name, ".") != 0) &&
                            (strcmp(tgt_grp_dir_entry->d_name, "..") != 0)) {
                        if (line_pos < MAX_ALUA_LAYOUT_LINES) {
                            snprintf(dir_name, MAX_SYSFS_PATH_SIZE,
                            "%s/device_groups/%s/target_groups/%s/group_id",
                            SYSFS_SCST_TGT, dev_grp_dir_entry->d_name,
                                    tgt_grp_dir_entry->d_name);
                            readAttribute(dir_name, tmp_buff);
                            SAFE_ASPRINTF(&swindow_info[line_pos],
                                    "\t</B>Target Group:<!B> %s (Group ID: %s)",
                                    tgt_grp_dir_entry->d_name, tmp_buff);
                            line_pos++;
                        }

                        /* Loop over each target name for the
                         * current target group */
                        snprintf(dir_name, MAX_SYSFS_PATH_SIZE,
                                "%s/device_groups/%s/target_groups/%s",
                                SYSFS_SCST_TGT, dev_grp_dir_entry->d_name,
                                tgt_grp_dir_entry->d_name);
                        if ((tgt_dir_stream = opendir(dir_name)) == NULL) {
                            if (line_pos < MAX_ALUA_LAYOUT_LINES) {
                                SAFE_ASPRINTF(&swindow_info[line_pos],
                                        "opendir(): %s", strerror(errno));
                                line_pos++;
                            }
                            break;
                        }
                        while ((tgt_dir_entry = readdir(tgt_dir_stream)) !=
                                NULL) {
                            /* The target names are links (if local),
                             * or directories (if remote); skip '.' and '..' */
                            if (((tgt_dir_entry->d_type == DT_DIR) &&
                                    (strcmp(tgt_dir_entry->d_name,
                                    ".") != 0) &&
                                    (strcmp(tgt_dir_entry->d_name,
                                    "..") != 0)) ||
                                    (tgt_dir_entry->d_type == DT_LNK)) {
                                if (line_pos < MAX_ALUA_LAYOUT_LINES) {
                                    snprintf(dir_name, MAX_SYSFS_PATH_SIZE,
                                            "%s/device_groups/%s/"
                                            "target_groups/%s/%s/rel_tgt_id",
                                            SYSFS_SCST_TGT,
                                            dev_grp_dir_entry->d_name,
                                            tgt_grp_dir_entry->d_name,
                                            tgt_dir_entry->d_name);
                                    readAttribute(dir_name, tmp_buff);
                                    SAFE_ASPRINTF(&swindow_info[line_pos],
                                            "\t\t</B>Target:<!B> %s "
                                            "(Rel Tgt ID: %s)",
                                            tgt_dir_entry->d_name, tmp_buff);
                                    line_pos++;
                                }
                            }
                        }
                        closedir(tgt_dir_stream);
                    }
                }
                closedir(tgt_grp_dir_stream);

                /* Print a blank line to separate targets */
                if (line_pos < MAX_ALUA_LAYOUT_LINES) {
                    SAFE_ASPRINTF(&swindow_info[line_pos], " ");
                    line_pos++;
                }
            }
        }
        closedir(dev_grp_dir_stream);
        break;
    }

    /* Add a message to the bottom explaining how to close the dialog */
    if (line_pos < MAX_ALUA_LAYOUT_LINES) {
        SAFE_ASPRINTF(&swindow_info[line_pos], " ");
        line_pos++;
    }
    if (line_pos < MAX_ALUA_LAYOUT_LINES) {
        SAFE_ASPRINTF(&swindow_info[line_pos], CONTINUE_MSG);
        line_pos++;
    }

    /* Set the scrolling window content */
    setCDKSwindowContents(alua_info, swindow_info, line_pos);

    /* The 'g' makes the swindow widget scroll to the top, then activate */
    injectCDKSwindow(alua_info, 'g');
    activateCDKSwindow(alua_info, 0);

    /* We fell through -- the user exited the widget, but we don't care how */
    destroyCDKSwindow(alua_info);

    /* Done */
    for (i = 0; i < MAX_ALUA_LAYOUT_LINES; i++)
        FREE_NULL(swindow_info[i]);
    return;
}
Example #21
0
/*
 * Run the Add Target to Group dialog
 */
void addTgtToGrpDialog(CDKSCREEN *main_cdk_screen) {
    WINDOW *add_tgt_window = 0;
    CDKSCREEN *add_tgt_screen = 0;
    CDKLABEL *add_tgt_info = 0;
    CDKENTRY *tgt_name = 0;
    CDKSCALE *rel_tgt_id = 0;
    CDKBUTTON *ok_button = 0, *cancel_button = 0;
    tButtonCallback ok_cb = &okButtonCB, cancel_cb = &cancelButtonCB;
    char dev_grp_name[MAX_SYSFS_ATTR_SIZE] = {0},
    tgt_grp_name[MAX_SYSFS_ATTR_SIZE] = {0},
    attr_path[MAX_SYSFS_PATH_SIZE] = {0},
    attr_value[MAX_SYSFS_ATTR_SIZE] = {0};
    char *error_msg = NULL;
    char *add_tgt_info_msg[TGT_GRP_INFO_LINES] = {NULL};
    int add_tgt_window_lines = 0, add_tgt_window_cols = 0, window_y = 0,
            window_x = 0, temp_int = 0, i = 0, traverse_ret = 0;

    /* Have the user choose a SCST device group */
    getSCSTDevGrpChoice(main_cdk_screen, dev_grp_name);
    if (dev_grp_name[0] == '\0')
        return;

    /* Get target group choice from user (based on previously
     * selected device group) */
    getSCSTTgtGrpChoice(main_cdk_screen, dev_grp_name, tgt_grp_name);
    if (tgt_grp_name[0] == '\0')
        return;

    /* New CDK screen */
    add_tgt_window_lines = 11;
    add_tgt_window_cols = 55;
    window_y = ((LINES / 2) - (add_tgt_window_lines / 2));
    window_x = ((COLS / 2) - (add_tgt_window_cols / 2));
    add_tgt_window = newwin(add_tgt_window_lines, add_tgt_window_cols,
            window_y, window_x);
    if (add_tgt_window == NULL) {
        errorDialog(main_cdk_screen, NEWWIN_ERR_MSG, NULL);
        return;
    }
    add_tgt_screen = initCDKScreen(add_tgt_window);
    if (add_tgt_screen == NULL) {
        errorDialog(main_cdk_screen, CDK_SCR_ERR_MSG, NULL);
        return;
    }
    boxWindow(add_tgt_window, COLOR_DIALOG_BOX);
    wbkgd(add_tgt_window, COLOR_DIALOG_TEXT);
    wrefresh(add_tgt_window);

    while (1) {
        /* Information label */
        SAFE_ASPRINTF(&add_tgt_info_msg[0],
                "</31/B>Adding SCST target to target group...");
        SAFE_ASPRINTF(&add_tgt_info_msg[1], " ");
        SAFE_ASPRINTF(&add_tgt_info_msg[2],
                "</B>Device group:<!B>\t%s", dev_grp_name);
        SAFE_ASPRINTF(&add_tgt_info_msg[3],
                "</B>Target group:<!B>\t%s", tgt_grp_name);
        add_tgt_info = newCDKLabel(add_tgt_screen, (window_x + 1),
                (window_y + 1), add_tgt_info_msg, ADD_TGT_INFO_LINES,
                FALSE, FALSE);
        if (!add_tgt_info) {
            errorDialog(main_cdk_screen, LABEL_ERR_MSG, NULL);
            break;
        }
        setCDKLabelBackgroundAttrib(add_tgt_info, COLOR_DIALOG_TEXT);

        /* Target name (entry) */
        tgt_name = newCDKEntry(add_tgt_screen, (window_x + 1), (window_y + 6),
                NULL, "</B>Target Name:         ",
                COLOR_DIALOG_SELECT, '_' | COLOR_DIALOG_INPUT, vMIXED,
                20, 0, SCST_TGT_NAME_LEN, FALSE, FALSE);
        if (!tgt_name) {
            errorDialog(main_cdk_screen, ENTRY_ERR_MSG, NULL);
            break;
        }
        setCDKEntryBoxAttribute(tgt_name, COLOR_DIALOG_INPUT);

        /* Relative target ID (scale) */
        rel_tgt_id = newCDKScale(add_tgt_screen, (window_x + 1), (window_y + 7),
                NULL, "</B>Relative Target ID: ", COLOR_DIALOG_SELECT,
                7, 0, MIN_SCST_REL_TGT_ID, MAX_SCST_REL_TGT_ID,
                1, 100, FALSE, FALSE);
        if (!rel_tgt_id) {
            errorDialog(main_cdk_screen, SCALE_ERR_MSG, NULL);
            break;
        }
        setCDKScaleBackgroundAttrib(rel_tgt_id, COLOR_DIALOG_TEXT);

        /* Buttons */
        ok_button = newCDKButton(add_tgt_screen, (window_x + 16),
                (window_y + 9), g_ok_cancel_msg[0], ok_cb, FALSE, FALSE);
        if (!ok_button) {
            errorDialog(main_cdk_screen, BUTTON_ERR_MSG, NULL);
            break;
        }
        setCDKButtonBackgroundAttrib(ok_button, COLOR_DIALOG_INPUT);
        cancel_button = newCDKButton(add_tgt_screen, (window_x + 26),
                (window_y + 9), g_ok_cancel_msg[1], cancel_cb, FALSE, FALSE);
        if (!cancel_button) {
            errorDialog(main_cdk_screen, BUTTON_ERR_MSG, NULL);
            break;
        }
        setCDKButtonBackgroundAttrib(cancel_button, COLOR_DIALOG_INPUT);

        /* Allow user to traverse the screen */
        refreshCDKScreen(add_tgt_screen);
        traverse_ret = traverseCDKScreen(add_tgt_screen);

        /* User hit 'OK' button */
        if (traverse_ret == 1) {
            /* Turn the cursor off (pretty) */
            curs_set(0);

            /* Check the entry field for bad characters */
            if (!checkInputStr(main_cdk_screen, INIT_CHARS,
                    getCDKEntryValue(tgt_name)))
                break;

            /* Add the target to the target group */
            snprintf(attr_path, MAX_SYSFS_PATH_SIZE,
                    "%s/device_groups/%s/target_groups/%s/mgmt",
                    SYSFS_SCST_TGT, dev_grp_name, tgt_grp_name);
            snprintf(attr_value, MAX_SYSFS_ATTR_SIZE, "add %s",
                    getCDKEntryValue(tgt_name));
            if ((temp_int = writeAttribute(attr_path, attr_value)) != 0) {
                SAFE_ASPRINTF(&error_msg,
                        "Couldn't add SCST (ALUA) target to target group: %s",
                        strerror(temp_int));
                errorDialog(main_cdk_screen, error_msg, NULL);
                FREE_NULL(error_msg);
                break;
            }

            /* Set the relative target ID */
            snprintf(attr_path, MAX_SYSFS_PATH_SIZE,
                    "%s/device_groups/%s/target_groups/%s/%s/rel_tgt_id",
                    SYSFS_SCST_TGT, dev_grp_name, tgt_grp_name,
                    getCDKEntryValue(tgt_name));
            snprintf(attr_value, MAX_SYSFS_ATTR_SIZE, "%d",
                    getCDKScaleValue(rel_tgt_id));
            if ((temp_int = writeAttribute(attr_path, attr_value)) != 0) {
                SAFE_ASPRINTF(&error_msg, SET_REL_TGT_ID_ERR, strerror(temp_int));
                errorDialog(main_cdk_screen, error_msg, NULL);
                FREE_NULL(error_msg);
                break;
            }
        }
        break;
    }

    /* Done */
    for (i = 0; i < ADD_TGT_INFO_LINES; i++)
        FREE_NULL(add_tgt_info_msg[i]);
    if (add_tgt_screen != NULL) {
        destroyCDKScreenObjects(add_tgt_screen);
        destroyCDKScreen(add_tgt_screen);
        delwin(add_tgt_window);
    }
    return;
}
Example #22
0
IGraphicsWin::~IGraphicsWin()
{
	CloseWindow();
  FREE_NULL(mCustomColorStorage);
}
Example #23
0
/*
 * Get "settable" adapter properties from MegaCLI.
 */
MRADPPROPS *getMRAdapterProps(int adapter_id) {
    MRADPPROPS *adp_props = 0;
    FILE *megacli = NULL;
    char *command = NULL, *strtok_result = NULL;
    char line[MAX_MC_LINE] = {0};
    int status = 0;

    adp_props = (MRADPPROPS *) calloc(1, sizeof(MRADPPROPS));
    if (adp_props != NULL) {
        adp_props->adapter_id = adapter_id;

        /* Get CacheFlushInterval */
        SAFE_ASPRINTF(&command, "%s -AdpGetProp CacheFlushInterval -a%d -NoLog 2>&1",
                      MEGACLI_BIN, adapter_id);
        megacli = popen(command, "r");
        while (fgets(line, sizeof(line), megacli) != NULL) {
            if (strstr(line, "Cache Flush Interval")) {
                strtok_result = strtok(line, "=");
                strtok_result = strtok(NULL, "=");
                sscanf(strStrip(strtok_result), "%d", &adp_props->cache_flush);
            }
        }
        status = pclose(megacli);
        FREE_NULL(command);
        if (status != 0) {
            return NULL;
        }

        /* Get RebuildRate */
        SAFE_ASPRINTF(&command, "%s -AdpGetProp RebuildRate -a%d -NoLog 2>&1",
                      MEGACLI_BIN, adapter_id);
        megacli = popen(command, "r");
        while (fgets(line, sizeof(line), megacli) != NULL) {
            if (strstr(line, "Rebuild Rate")) {
                strtok_result = strtok(line, "=");
                strtok_result = strtok(NULL, "=");
                sscanf(strStrip(strtok_result), "%d", &adp_props->rebuild_rate);
            }
        }
        status = pclose(megacli);
        FREE_NULL(command);
        if (status != 0) {
            return NULL;
        }

        /* Get ClusterEnable */
        SAFE_ASPRINTF(&command, "%s -AdpGetProp ClusterEnable -a%d -NoLog 2>&1",
                      MEGACLI_BIN, adapter_id);
        megacli = popen(command, "r");
        while (fgets(line, sizeof(line), megacli) != NULL) {
            if (strstr(line, "Cluster :")) {
                strtok_result = strtok(line, ":");
                strtok_result = strtok(NULL, ":");
                strtok_result = strtok(NULL, ":");
                if (strcmp(strStrip(strtok_result), "Enabled") == 0) {
                    adp_props->cluster = TRUE;
                } else if (strcmp(strStrip(strtok_result), "Disabled") == 0) {
                    adp_props->cluster = FALSE;
                }
            }
        }
        status = pclose(megacli);
        FREE_NULL(command);
        if (status != 0) {
            return NULL;
        }

        /* Get NCQDsply */
        SAFE_ASPRINTF(&command, "%s -AdpGetProp NCQDsply -a%d -NoLog 2>&1",
                      MEGACLI_BIN, adapter_id);
        megacli = popen(command, "r");
        while (fgets(line, sizeof(line), megacli) != NULL) {
            if (strstr(line, "NCQ Status is")) {
                strtok_result = strtok(line, ":");
                strtok_result = strtok(NULL, ":");
                if (strcmp(strStrip(strtok_result),
                           "NCQ Status is Enabled") == 0) {
                    adp_props->ncq = TRUE;
                } else if (strcmp(strStrip(strtok_result),
                                  "NCQ Status is Disabled") == 0) {
                    adp_props->ncq = FALSE;
                }
            }
        }
        status = pclose(megacli);
        FREE_NULL(command);
        if (status != 0) {
            FREE_NULL(adp_props);
            return NULL;
        }
    }

    /* Done */
    return adp_props;
}
Example #24
0
/*
 * Get MegaRAID enclosure information; not happy about how this is
 * implemented -- if LSI could have just made all of the MegaCLI commands
 * uniform (eg, be able to specify an enclosure like you specify an adapter)!
 */
MRENCL *getMREnclosure(int adapter_id, int encl_id) {
    MRENCL *enclosure = 0;
    FILE *megacli = NULL;
    char *command = NULL, *strtok_result = NULL;
    char line[MAX_MC_LINE] = {0};
    int status = 0;
    int counters[] = {0, 0, 0, 0, 0, 0, 0};

    enclosure = (MRENCL *) calloc(1, sizeof(MRENCL));
    if (enclosure != NULL) {
        enclosure->adapter_id = adapter_id;

        /* MegaCLI command */
        SAFE_ASPRINTF(&command, "%s -EncInfo -a%d -NoLog 2>&1",
                      MEGACLI_BIN, adapter_id);
        megacli = popen(command, "r");

        /* Loop over command output */
        while (fgets(line, sizeof(line), megacli) != NULL) {
            if (strstr(line, "    Device ID                     :")) {
                strtok_result = strtok(line, ":");
                strtok_result = strtok(NULL, ":");
                if (counters[0] == encl_id)
                    sscanf(strtok_result, " %d", &enclosure->device_id);
                counters[0]++;

            } else if (strstr(line, "    Number of Slots               :")) {
                strtok_result = strtok(line, ":");
                strtok_result = strtok(NULL, ":");
                if (counters[1] == encl_id)
                    sscanf(strtok_result, " %d", &enclosure->slots);
                counters[1]++;

            } else if (strstr(line, "    Number of Power Supplies      :")) {
                strtok_result = strtok(line, ":");
                strtok_result = strtok(NULL, ":");
                if (counters[2] == encl_id)
                    sscanf(strtok_result, " %d", &enclosure->power_supps);
                counters[2]++;

            } else if (strstr(line, "    Number of Fans                :")) {
                strtok_result = strtok(line, ":");
                strtok_result = strtok(NULL, ":");
                if (counters[3] == encl_id)
                    sscanf(strtok_result, " %d", &enclosure->fans);
                counters[3]++;

            } else if (strstr(line, "    Status                        :")) {
                strtok_result = strtok(line, ":");
                strtok_result = strtok(NULL, ":");
                if (counters[4] == encl_id)
                    strncpy(enclosure->status, strStrip(strtok_result),
                            MAX_MR_ATTR_SIZE);
                counters[4]++;

            } else if (strstr(line, "        Vendor Identification     :")) {
                strtok_result = strtok(line, ":");
                strtok_result = strtok(NULL, ":");
                if (counters[5] == encl_id)
                    strncpy(enclosure->vendor, strStrip(strtok_result),
                            MAX_MR_ATTR_SIZE);
                counters[5]++;

            } else if (strstr(line, "        Product Identification    :")) {
                strtok_result = strtok(line, ":");
                strtok_result = strtok(NULL, ":");
                if (counters[6] == encl_id)
                    strncpy(enclosure->product, strStrip(strtok_result),
                            MAX_MR_ATTR_SIZE);
                counters[6]++;
            }
        }

        /* Done with MegaCLI */
        status = pclose(megacli);
        FREE_NULL(command);
        if (status != 0) {
            FREE_NULL(enclosure);
            return NULL;
        }
    }

    /* Done */
    return enclosure;
}
Example #25
0
/*
 * Get MegaRAID disk information.
 */
MRDISK *getMRDisk(int adapter_id, int encl_id, int slot) {
    MRDISK *disk = 0;
    FILE *megacli = NULL;
    char *command = NULL, *strtok_result = NULL;
    char line[MAX_MC_LINE] = {0};
    int status = 0;

    disk = (MRDISK *) calloc(1, sizeof(MRDISK));
    if (disk != NULL) {
        disk->adapter_id = adapter_id;
        disk->present = TRUE;
        disk->part_of_ld = FALSE;

        /* MegaCLI command */
        SAFE_ASPRINTF(&command, "%s -pdInfo -PhysDrv[%d:%d] -a%d -NoLog 2>&1",
                      MEGACLI_BIN, encl_id, slot, adapter_id);
        megacli = popen(command, "r");

        /* Loop over command output */
        while (fgets(line, sizeof(line), megacli) != NULL) {
            if (strstr(line, "is not found.")) {
                /* A disk isn't present in the specified slot */
                disk->present = FALSE;
                continue;

            } else if (strstr(line, "Enclosure Device ID:")) {
                sscanf(line, "%*s %*s %*s %d", &disk->enclosure_id);

            } else if (strstr(line, "Slot Number:")) {
                sscanf(line, "%*s %*s %d", &disk->slot_num);

            } else if (strstr(line, "PD Type:")) {
                strtok_result = strtok(line, ":");
                strtok_result = strtok(NULL, ":");
                strncpy(disk->pd_type, strStrip(strtok_result),
                        MAX_MR_ATTR_SIZE);

            } else if (strstr(line, "Raw Size:")) {
                strtok_result = strtok(line, ":");
                strtok_result = strtok(NULL, ":");
                strncpy(disk->raw_size, strStrip(strtok_result),
                        MAX_MR_ATTR_SIZE);

            } else if (strstr(line, "Firmware state:")) {
                strtok_result = strtok(line, ":");
                strtok_result = strtok(NULL, ":");
                strncpy(disk->state, strStrip(strtok_result),
                        MAX_MR_ATTR_SIZE);

            } else if (strstr(line, "Inquiry Data:")) {
                strtok_result = strtok(line, ":");
                strtok_result = strtok(NULL, ":");
                strncpy(disk->inquiry, strStrip(strtok_result),
                        MAX_MR_ATTR_SIZE);

            } else if (strstr(line, "Link Speed:")) {
                strtok_result = strtok(line, ":");
                strtok_result = strtok(NULL, ":");
                strncpy(disk->speed, strStrip(strtok_result),
                        MAX_MR_ATTR_SIZE);

            } else if (strstr(line, "Drive's position:")) {
                /* If the PD entry contains the string above, then its
                 * part of a logical drive (LD). */
                disk->part_of_ld = TRUE;
            }
        }

        /* Done with MegaCLI */
        status = pclose(megacli);
        FREE_NULL(command);
        if (status != 0) {
            FREE_NULL(disk);
            return NULL;
        }
    }

    /* Done */
    return disk;
}
Example #26
0
IPopupMenu* IGraphicsWin::CreateIPopupMenu(IPopupMenu* pMenu, IRECT* pAreaRect)
{
  ReleaseMouseCapture();
  
  int numItems = pMenu->GetNItems();

  POINT cPos;
  
  cPos.x = pAreaRect->L;
  cPos.y = pAreaRect->B;

  ClientToScreen(mPlugWnd, &cPos);

  HMENU hMenu = CreatePopupMenu();

  int flags = 0;
  
  if(numItems && hMenu)
  {
    for(int i = 0; i< numItems;i++)
    {
      IPopupMenuItem* menuItem = pMenu->GetItem(i);

      if (menuItem->GetIsSeparator())
      {
        AppendMenu (hMenu, MF_SEPARATOR, 0, 0);
      }
      else
      {
        const char* str = menuItem->GetText();
        char* titleWithPrefixNumbers = 0;
        
        if (pMenu->GetPrefix())
        {
          titleWithPrefixNumbers = (char*)malloc(strlen(str) + 50);

          switch (pMenu->GetPrefix())
          {
            case 1:
            {
              sprintf(titleWithPrefixNumbers, "%1d: %s", i+1, str); break;
            }
            case 2:
            {
              sprintf(titleWithPrefixNumbers, "%02d: %s", i+1, str); break;
            }
            case 3:
            {
              sprintf(titleWithPrefixNumbers, "%03d: %s", i+1, str); break;
            }
          }
        }

        const char* entryText (titleWithPrefixNumbers ? titleWithPrefixNumbers : str);
        
        flags = MF_STRING;
        //if (nbEntries < 160 && _menu->getNbItemsPerColumn () > 0 && inc && !(inc % _menu->getNbItemsPerColumn ()))
        //  flags |= MF_MENUBARBREAK;

        if (menuItem->GetSubmenu())
        {
        //  HMENU submenu = createMenu (item->getSubmenu (), offsetIdx);
        //  if (submenu)
        //  {
         //   AppendMenu (menu, flags|MF_POPUP|MF_ENABLED, (UINT_PTR)submenu, (const TCHAR*)entryText);
         // }
        }
        else
        {
          if (menuItem->GetEnabled())
            flags |= MF_ENABLED;
          else
            flags |= MF_GRAYED;
          if (menuItem->GetIsTitle())
            flags |= MF_DISABLED;
          //if (multipleCheck && menuItem->GetChecked())
           // flags |= MF_CHECKED;
          if (menuItem->GetChecked())
            flags |= MF_CHECKED;
          else
            flags |= MF_UNCHECKED;
          //if (!(flags & MF_CHECKED))
          //  flags |= MF_UNCHECKED;
          
          AppendMenu(hMenu, flags, i+1, entryText);
          
        }

        if(titleWithPrefixNumbers)
          FREE_NULL(titleWithPrefixNumbers);
      }
    }
    
    int itemChosen = TrackPopupMenu(hMenu, TPM_LEFTALIGN/*|TPM_VCENTERALIGN*/|TPM_NONOTIFY|TPM_RETURNCMD, cPos.x, cPos.y, 0, mPlugWnd, 0);

//    IPopupMenu* chosenMenu;

 

    if (itemChosen > 0)
    {
      pMenu->SetChosenItemIdx(itemChosen - 1);
      DestroyMenu(hMenu);
      return pMenu;
    }
    else 
    {
      DestroyMenu(hMenu);
      return 0;
    }
  }
  else 
  return 0;
}