Re: svn commit: r309374 - in head: sbin/camcontrol sys/cam/scsi

2016-12-03 Thread Conrad Meyer
On Fri, Dec 2, 2016 at 9:38 PM, Ravi Pokala  wrote:
> -Original Message-
>> From:  on behalf of Kyle Evans 
>> 
>>
>> I understand that this is a bogus error because at this point it
>> pretty much *has* to be set by the report_timestamp call just prior,
>> but is there a clean way to trick GCC into agreeing, or is it just a
>> matter of explicitly initializing it to 0 before the report_timestamp
>> call?
>
> Actually, it's a valid warning. While all paths to that point in timestamp() 
> go through report_timestamp(), not all paths through report_timestamp() set 
> *ts. Specifically, if cam_getccb() or cam_send_ccb() fail, or the request was 
> not completed, report_timestamp() does 'goto bailout' without setting *ts.

But in that case, report_timestamp() returns a non-zero error.  And
timestamp() will goto its own bailout, avoiding use of an unset value.

> I'm disappointed that `clang' (on i386 and amd64) didn't notice this; I was 
> under the impression `clang' did more of that type of deep path analysis than 
> `gcc'. 

I think it's purely spurious, although understandably difficult for
the compiler to notice.  Adrian's proposed zero initialization seems
like a fine fix.

Best,
Conrad
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r309374 - in head: sbin/camcontrol sys/cam/scsi

2016-12-02 Thread Ravi Pokala
-Original Message-
> From:  on behalf of Kyle Evans 
> 
> Date: 2016-12-02, Friday at 20:44
> To: "Kenneth D. Merry" 
> Cc: , , 
> 
> Subject: Re: svn commit: r309374 - in head: sbin/camcontrol sys/cam/scsi
> 
>> [...]
>> +
>> +   if (action == TIMESTAMP_REPORT) {
>> +   error = report_timestamp(device, &ts, retry_count,
>> +   timeout);
>> +   if (error != 0) {
>> +   goto bailout;
>> +   } else if (strcmp(format_string, MIL) == 0) {
>> +   printf("Timestamp in milliseconds: %ju\n",
>> +   (uintmax_t)ts);
>> +   } else {
>> +   char temp_timestamp_string[100];
>> +   time_t time_var = ts / 1000;
> 
> Hi,
> 
> FWIW: Building -CURRENT on mips.mips (w/ freebsd-wifi-build),
> mips-gcc gets upset at the above line with the following error:
> 
> /wifi-build/src/sbin/camcontrol/timestamp.c: In function 'timestamp':
> /wifi-build/src/sbin/camcontrol/timestamp.c:459:25: error: 'ts' may be
> used uninitialized in this function [-Werror=maybe-uninitialized]
> time_t time_var = ts / 1000;

Interesting. I just did a tinderbox build earlier this evening, and this wasn't 
reported.

> I understand that this is a bogus error because at this point it
> pretty much *has* to be set by the report_timestamp call just prior,
> but is there a clean way to trick GCC into agreeing, or is it just a
> matter of explicitly initializing it to 0 before the report_timestamp
> call?

Actually, it's a valid warning. While all paths to that point in timestamp() go 
through report_timestamp(), not all paths through report_timestamp() set *ts. 
Specifically, if cam_getccb() or cam_send_ccb() fail, or the request was not 
completed, report_timestamp() does 'goto bailout' without setting *ts.

I'm disappointed that `clang' (on i386 and amd64) didn't notice this; I was 
under the impression `clang' did more of that type of deep path analysis than 
`gcc'. 

-Ravi (rpokala@)

> Thanks,
> 
> Kyle Evans



___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


Re: svn commit: r309374 - in head: sbin/camcontrol sys/cam/scsi

2016-12-02 Thread Kyle Evans
On Thu, Dec 1, 2016 at 4:20 PM, Kenneth D. Merry  wrote:
> Author: ken
> Date: Thu Dec  1 22:20:27 2016
> New Revision: 309374
> URL: https://svnweb.freebsd.org/changeset/base/309374
>
> Log:
>   Add SCSI REPORT TIMESTAMP and SET TIMESTAMP support.
>
>   This adds support to camcontrol(8) and libcam(3) for getting and setting
>   the time on SCSI protocol drives.  This is more commonly found on tape
>   drives, but is a SPC (SCSI Primary Commands) command, and may be found
>   on any device that speaks SCSI.
>
>   The new camcontrol timestamp subcommand allows getting the current device
>   time or setting the time to the current system time or any arbitrary time.
>
>   sbin/camcontrol/Makefile:
> Add timestamp.c.
>
>   sbin/camcontrol/camcontrol.8:
> Document the new timestamp subcommand.
>
>   sbin/camcontrol/camcontrol.c:
> Add the timestamp subcommand to camcontrol.
>
>   sbin/camcontrol/camcontrol.h:
> Add the timestamp() function prototype.
>
>   sbin/camcontrol/timestamp.c:
> Timestamp setting and reporting functionality.
>
>   sys/cam/scsi/scsi_all.c:
> Add two new CCB building functions, scsi_set_timestamp() and
> scsi_report_timestamp().  Also, add a new helper function,
> scsi_create_timestamp().
>
>   sys/cam/scsi/scsi_all.h:
> Add CDB and parameter data for the the set and report timestamp
> commands.
>
> Add function declarations for the new CCB building and helper
> functions.
>
>   Submitted by: Sam Klopsch
>   Sponsored by: Spectra Logic
>   MFC After:2 weeks
>
> Added:
>   head/sbin/camcontrol/timestamp.c   (contents, props changed)
> Modified:
>   head/sbin/camcontrol/Makefile
>   head/sbin/camcontrol/camcontrol.8
>   head/sbin/camcontrol/camcontrol.c
>   head/sbin/camcontrol/camcontrol.h
>   head/sys/cam/scsi/scsi_all.c
>   head/sys/cam/scsi/scsi_all.h
>
> Modified: head/sbin/camcontrol/Makefile
> ...
> +timestamp(struct cam_device *device, int argc, char **argv, char 
> *combinedopt,
> + int retry_count, int timeout, int verbosemode __unused)
> +{
> +   int c;
> +   uint64_t ts;
> +   char *format_string = NULL;
> +   char *timestamp_string = NULL;
> +   int action = -1;
> +   int error = 0;
> +   int single_arg = 0;
> +   int do_utc = 0;
> +
> +   if (action == TIMESTAMP_REPORT) {
> +   error = report_timestamp(device, &ts, retry_count,
> +   timeout);
> +   if (error != 0) {
> +   goto bailout;
> +   } else if (strcmp(format_string, MIL) == 0) {
> +   printf("Timestamp in milliseconds: %ju\n",
> +   (uintmax_t)ts);
> +   } else {
> +   char temp_timestamp_string[100];
> +   time_t time_var = ts / 1000;

Hi,

FWIW: Building -CURRENT on mips.mips (w/ freebsd-wifi-build),
mips-gcc gets upset at the above line with the following error:

/wifi-build/src/sbin/camcontrol/timestamp.c: In function 'timestamp':
/wifi-build/src/sbin/camcontrol/timestamp.c:459:25: error: 'ts' may be
used uninitialized in this function [-Werror=maybe-uninitialized]
time_t time_var = ts / 1000;

I understand that this is a bogus error because at this point it
pretty much *has* to be set by the report_timestamp call just prior,
but is there a clean way to trick GCC into agreeing, or is it just a
matter of explicitly initializing it to 0 before the report_timestamp
call?

Thanks,

Kyle Evans
___
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"


svn commit: r309374 - in head: sbin/camcontrol sys/cam/scsi

2016-12-01 Thread Kenneth D. Merry
Author: ken
Date: Thu Dec  1 22:20:27 2016
New Revision: 309374
URL: https://svnweb.freebsd.org/changeset/base/309374

Log:
  Add SCSI REPORT TIMESTAMP and SET TIMESTAMP support.
  
  This adds support to camcontrol(8) and libcam(3) for getting and setting
  the time on SCSI protocol drives.  This is more commonly found on tape
  drives, but is a SPC (SCSI Primary Commands) command, and may be found
  on any device that speaks SCSI.
  
  The new camcontrol timestamp subcommand allows getting the current device
  time or setting the time to the current system time or any arbitrary time.
  
  sbin/camcontrol/Makefile:
Add timestamp.c.
  
  sbin/camcontrol/camcontrol.8:
Document the new timestamp subcommand.
  
  sbin/camcontrol/camcontrol.c:
Add the timestamp subcommand to camcontrol.
  
  sbin/camcontrol/camcontrol.h:
Add the timestamp() function prototype.
  
  sbin/camcontrol/timestamp.c:
Timestamp setting and reporting functionality.
  
  sys/cam/scsi/scsi_all.c:
Add two new CCB building functions, scsi_set_timestamp() and
scsi_report_timestamp().  Also, add a new helper function,
scsi_create_timestamp().
  
  sys/cam/scsi/scsi_all.h:
Add CDB and parameter data for the the set and report timestamp
commands.
  
Add function declarations for the new CCB building and helper
functions.
  
  Submitted by: Sam Klopsch
  Sponsored by: Spectra Logic
  MFC After:2 weeks

Added:
  head/sbin/camcontrol/timestamp.c   (contents, props changed)
Modified:
  head/sbin/camcontrol/Makefile
  head/sbin/camcontrol/camcontrol.8
  head/sbin/camcontrol/camcontrol.c
  head/sbin/camcontrol/camcontrol.h
  head/sys/cam/scsi/scsi_all.c
  head/sys/cam/scsi/scsi_all.h

Modified: head/sbin/camcontrol/Makefile
==
--- head/sbin/camcontrol/Makefile   Thu Dec  1 22:12:58 2016
(r309373)
+++ head/sbin/camcontrol/Makefile   Thu Dec  1 22:20:27 2016
(r309374)
@@ -4,7 +4,7 @@ PACKAGE=runtime
 PROG=  camcontrol
 SRCS=  camcontrol.c util.c
 .if !defined(RELEASE_CRUNCH)
-SRCS+= attrib.c epc.c fwdownload.c modeedit.c persist.c progress.c zone.c
+SRCS+= attrib.c epc.c fwdownload.c modeedit.c persist.c progress.c timestamp.c 
zone.c
 .else
 CFLAGS+= -DMINIMALISTIC
 .endif

Modified: head/sbin/camcontrol/camcontrol.8
==
--- head/sbin/camcontrol/camcontrol.8   Thu Dec  1 22:12:58 2016
(r309373)
+++ head/sbin/camcontrol/camcontrol.8   Thu Dec  1 22:20:27 2016
(r309374)
@@ -27,7 +27,7 @@
 .\"
 .\" $FreeBSD$
 .\"
-.Dd May 16, 2016
+.Dd November 30, 2016
 .Dt CAMCONTROL 8
 .Os
 .Sh NAME
@@ -343,6 +343,11 @@
 .Op Fl S Ar power_src
 .Op Fl T Ar timer
 .Nm
+.Ic timestamp
+.Op device id
+.Op generic args
+.Ao Fl r Oo Ns Fl f Ar format | Fl m | Fl U Oc | Fl s Ao Fl f Ar format Fl T 
Ar time | Fl U Ac Ac
+.Nm
 .Ic help
 .Sh DESCRIPTION
 The
@@ -2417,6 +2422,54 @@ supports, and a number of parameters abo
 whether it is enabled and what the timer value is.
 .El
 .El
+.It Ic timestamp
+Issue REPORT TIMESTAMP or SET TIMESTAMP
+.Tn SCSI
+commands. Either the
+.Fl r
+option or the
+.Fl s
+option must be specified.
+.Bl -tag -width 6n
+.It Fl r
+Report the device's timestamp.
+If no more arguments are specified, the timestamp will be reported using
+the national representation of the date and time, followed by the time
+zone.
+.Bl -tag -width 9n
+.It Fl f Ar format
+Specify the strftime format string, as documented in strftime(3), to be used
+to format the reported timestamp.
+.It Fl m
+Report the timestamp as milliseconds since the epoch.
+.It Fl U
+Report the timestamp using the national representation of the date and
+time, but override the system time zone and use UTC instead.
+.El
+.El
+.Bl -tag -width 6n
+.It Fl s
+Set the device's timestamp. Either the
+.Fl f
+and 
+.Fl T
+options or the
+.Fl U
+option must be specified.
+.Bl -tag -width 9n
+.It Fl f Ar format
+Specify the strptime format string, as documented in strptime(3).
+The time must also be specified with the
+.Fl T 
+option.
+.It Fl T
+Provide the time in the format specified with the
+.Fl f
+option.
+.It Fl U
+Set the timestamp to the host system's time in UTC.
+.El
+.El
 .It Ic help
 Print out verbose usage information.
 .El
@@ -2730,6 +2783,18 @@ camcontrol epc ada0 -c list
 Display the ATA Power Conditions log (Log Address 0x08) for
 drive
 .Pa ada0 .
+.Pp
+.Bd -literal -offset indent
+camcontrol timestamp sa0 -s -f "%A %c" \e
+   -T "Wednesday Wed Oct 26 21:43:57 2016"
+.Ed
+.Pp
+Set the timestamp of drive
+.Pa sa0
+using a
+.Xr strptime 3 
+format string followed by a time string
+that was created using this format string.
 .Sh SEE ALSO
 .Xr cam 3 ,
 .Xr cam_cdbparse 3 ,

Modified: head/sbin/camcontrol/camcontrol.c
==
--- head/sbin