Skip to content

Commit 841a8ab

Browse files
committed
Also check for deconfigured and check-stopped cards
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 <jschmidb@de.ibm.com>
1 parent 6e17971 commit 841a8ab

1 file changed

Lines changed: 41 additions & 13 deletions

File tree

src/s390_crypto.c

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -326,22 +326,37 @@ static void set_switches(int msa)
326326
*s390_kdsa_functions[n].enabled = 1;
327327
}
328328

329-
unsigned int is_device_online(const char *dev)
329+
int file_fgets(const char *fname, char *buf, size_t buflen)
330330
{
331-
unsigned int ret = 0;
332-
FILE *file;
333-
char c;
331+
FILE *fp;
332+
char *end;
333+
int rc = 0;
334334

335-
if ((file = fopen(dev, "r")) == NULL)
336-
return 0;
335+
buf[0] = '\0';
337336

338-
/* Check if device online: 0 = offline, 1 = online */
339-
if ((c = fgetc(file)) == '1')
340-
ret = 1;
337+
fp = fopen(fname, "r");
338+
if (fp == NULL) {
339+
return EIO;
340+
}
341+
if (fgets(buf, buflen, fp) == NULL) {
342+
rc = EIO;
343+
goto out_fclose;
344+
}
341345

342-
fclose(file);
346+
end = memchr(buf, '\n', buflen);
347+
if (end)
348+
*end = 0;
349+
else
350+
buf[buflen - 1] = 0;
343351

344-
return ret;
352+
if (strlen(buf) == 0) {
353+
rc = EIO;
354+
goto out_fclose;
355+
}
356+
357+
out_fclose:
358+
fclose(fp);
359+
return rc;
345360
}
346361

347362
unsigned int get_device_type(const char *dev, char *devtype)
@@ -381,8 +396,10 @@ unsigned int search_for_cards()
381396
DIR *sysDir;
382397
unsigned int ret = 0;
383398
char dev[MAX_DEV_LEN] = AP_PATH;
399+
char buf[250];
384400
struct dirent *direntp;
385401
char type[6];
402+
int rc;
386403

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

396-
/* Check if device online */
413+
/* Check if device online, configured, and not in checkstop */
397414
snprintf(dev, MAX_DEV_LEN, "%s/%s/online", AP_PATH, direntp->d_name);
398-
if (!is_device_online(dev))
415+
rc = file_fgets(dev, buf, sizeof(buf));
416+
if (rc != 0 || strcmp(buf, "1") != 0)
417+
continue;
418+
419+
snprintf(dev, MAX_DEV_LEN, "%s/%s/config", AP_PATH, direntp->d_name);
420+
rc = file_fgets(dev, buf, sizeof(buf));
421+
if (rc == 0 && strcmp(buf, "1") != 0)
422+
continue;
423+
424+
snprintf(dev, MAX_DEV_LEN, "%s/%s/chkstop", AP_PATH, direntp->d_name);
425+
rc = file_fgets(dev, buf, sizeof(buf));
426+
if (rc == 0 && strcmp(buf, "0") != 0)
399427
continue;
400428

401429
/* Get device type (string like "CEXnT") */

0 commit comments

Comments
 (0)