PowerPC: honor O_NONBLOCK flag for rtas error_log
PATCH 1/1 PowerPC: honor O_NONBLOCK flag for rtas error_log
rtas_log_read() currently doesn't count O_NONBLOCK flag. This sample code will block on read:
fd = open ("/proc/ppc64/rtas/error_log", O_RDONLY | O_NONBLOCK);
while (1) {
err =read (fd, buf, 4096);
printf("err = %d, errno = %d (%s)\n", err, errno, strerror(errno));
sleep(1);
}With patched kernel it produces such (correct) output:
err = 2052, errno = 0 (Success)
err = -1, errno = 11 (Resource temporarily unavailable) err = -1, errno = 11 (Resource temporarily unavailable) err = -1, errno = 11 (Resource temporarily unavailable) err = -1, errno = 11 (Resource temporarily unavailable)
arch/powerpc/platforms/pseries/rtasd.c +10 -7
@@ -291,22 +291,25 @@ static ssize_t rtas_log_read(struct file * file, char __user * buf,if (!access_ok (VERIFY_WRITE , buf, count))return -EFAULT ; - tmp =kmalloc (count,GFP_KERNEL ); -if (!tmp) -return -ENOMEM ; - -spin_lock_irqsave (&rtasd_log_lock, s);/* if it's 0, then we know we got the last one (the one in NVRAM) */ -if (rtas_log_size ==0 && logging_enabled) +if (rtas_log_size ==0 && logging_enabled) {nvram_clear_error_log (); +if (file->f_flags &O_NONBLOCK ) { +spin_unlock_irqrestore (&rtasd_log_lock, s); +return -EAGAIN ; + } + }spin_unlock_irqrestore (&rtasd_log_lock, s); - error =wait_event_interruptible (rtas_log_wait, rtas_log_size);if (error) goto out; + tmp =kmalloc (count,GFP_KERNEL ); +if (!tmp) +return -ENOMEM ; +spin_lock_irqsave (&rtasd_log_lock, s); offset = rtas_error_log_buffer_max * (rtas_log_start &LOG_NUMBER_MASK );memcpy (tmp, &rtas_log_buf[offset], count);
Signature · 1 line
wbr, Vitaly
Quoted 10 lines · Vitaly Mayatskikh
rtas_log_read()currently doesn't countO_NONBLOCKflag. This sample code will block on read:fd = open ("/proc/ppc64/rtas/error_log", O_RDONLY | O_NONBLOCK); while (1) { err =read (fd, buf, 4096); printf("err = %d, errno = %d (%s)\n", err, errno, strerror(errno)); sleep(1); }
Quoted 7 lines
With patched kernel it produces such (correct) output:
err = 2052, errno = 0 (Success)
err = -1, errno = 11 (Resource temporarily unavailable) err = -1, errno = 11 (Resource temporarily unavailable) err = -1, errno = 11 (Resource temporarily unavailable) err = -1, errno = 11 (Resource temporarily unavailable)
Sorry, wrong patch :(
arch/powerpc/platforms/pseries/rtasd.c +11 -8
@@ -291,21 +291,24 @@ static ssize_t rtas_log_read(struct file * file, char __user * buf,if (!access_ok (VERIFY_WRITE , buf, count))return -EFAULT ; - tmp =kmalloc (count,GFP_KERNEL ); -if (!tmp) -return -ENOMEM ; - -spin_lock_irqsave (&rtasd_log_lock, s);/* if it's 0, then we know we got the last one (the one in NVRAM) */ -if (rtas_log_size ==0 && logging_enabled) +if (rtas_log_size ==0 && logging_enabled) {nvram_clear_error_log (); +if (file->f_flags &O_NONBLOCK ) { +spin_unlock_irqrestore (&rtasd_log_lock, s); +return -EAGAIN ; + } + }spin_unlock_irqrestore (&rtasd_log_lock, s); - error =wait_event_interruptible (rtas_log_wait, rtas_log_size);if (error) - goto out; +return error; + + tmp =kmalloc (count,GFP_KERNEL ); +if (!tmp) +return -ENOMEM ;spin_lock_irqsave (&rtasd_log_lock, s); offset = rtas_error_log_buffer_max * (rtas_log_start &LOG_NUMBER_MASK );
Signature · 1 line
wbr, Vitaly