Skip to content

Commit

Permalink
Also check for deconfigured and check-stopped cards
Browse files Browse the repository at this point in the history
When checking if a device is online, not only check the 'online' sysfs
attribute, but also check the 'config' and 'chkstop' attributes. Cards
and APQNs in check-stopped or deconfigured state can still be reported
as online via the sysfs attribute, although they are not available.
In case the 2 additional sysfs attributes are not available in sysfs,
then just rely on the 'online' attribute only.

Signed-off-by: Joerg Schmidbauer <[email protected]>
  • Loading branch information
jschmidb committed Jan 22, 2024
1 parent 6e17971 commit 841a8ab
Showing 1 changed file with 41 additions and 13 deletions.
54 changes: 41 additions & 13 deletions src/s390_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,22 +326,37 @@ static void set_switches(int msa)
*s390_kdsa_functions[n].enabled = 1;
}

unsigned int is_device_online(const char *dev)
int file_fgets(const char *fname, char *buf, size_t buflen)
{
unsigned int ret = 0;
FILE *file;
char c;
FILE *fp;
char *end;
int rc = 0;

if ((file = fopen(dev, "r")) == NULL)
return 0;
buf[0] = '\0';

/* Check if device online: 0 = offline, 1 = online */
if ((c = fgetc(file)) == '1')
ret = 1;
fp = fopen(fname, "r");
if (fp == NULL) {
return EIO;
}
if (fgets(buf, buflen, fp) == NULL) {
rc = EIO;
goto out_fclose;
}

fclose(file);
end = memchr(buf, '\n', buflen);
if (end)
*end = 0;
else
buf[buflen - 1] = 0;

return ret;
if (strlen(buf) == 0) {
rc = EIO;
goto out_fclose;
}

out_fclose:
fclose(fp);
return rc;
}

unsigned int get_device_type(const char *dev, char *devtype)
Expand Down Expand Up @@ -381,8 +396,10 @@ unsigned int search_for_cards()
DIR *sysDir;
unsigned int ret = 0;
char dev[MAX_DEV_LEN] = AP_PATH;
char buf[250];
struct dirent *direntp;
char type[6];
int rc;

if ((sysDir = opendir(dev)) == NULL)
return 0;
Expand All @@ -393,9 +410,20 @@ unsigned int search_for_cards()
if (strncmp(direntp->d_name, "card", 4) != 0)
continue;

/* Check if device online */
/* Check if device online, configured, and not in checkstop */
snprintf(dev, MAX_DEV_LEN, "%s/%s/online", AP_PATH, direntp->d_name);
if (!is_device_online(dev))
rc = file_fgets(dev, buf, sizeof(buf));
if (rc != 0 || strcmp(buf, "1") != 0)
continue;

snprintf(dev, MAX_DEV_LEN, "%s/%s/config", AP_PATH, direntp->d_name);
rc = file_fgets(dev, buf, sizeof(buf));
if (rc == 0 && strcmp(buf, "1") != 0)
continue;

snprintf(dev, MAX_DEV_LEN, "%s/%s/chkstop", AP_PATH, direntp->d_name);
rc = file_fgets(dev, buf, sizeof(buf));
if (rc == 0 && strcmp(buf, "0") != 0)
continue;

/* Get device type (string like "CEXnT") */
Expand Down

0 comments on commit 841a8ab

Please sign in to comment.