Skip to content

SCSI Dump Usability Enhancements & Cleanup#1026

Merged
akuker merged 16 commits intodevelopfrom
feature_scsidump_usability
Dec 9, 2022
Merged

SCSI Dump Usability Enhancements & Cleanup#1026
akuker merged 16 commits intodevelopfrom
feature_scsidump_usability

Conversation

@akuker
Copy link
Copy Markdown
Member

@akuker akuker commented Dec 8, 2022

  • Fix for weird corner case - when executing the arm binary on an x86_64 host, PiSCSI will throw an exception while trying to initialize the GPIO bus. This isn't a valid use case, so just handling the exception and aborting execution. (TIL - Ubuntu 22 on x86_64 will still execute an ARM binary. It seems to spin up Qemu in the background to try to run the executable)
  • Rename RasDump to ScsiDump
  • Add total time and transfer rate to the output of scsidump
  • Create a .properties file when backing up a drive. This can be used to more closely emulate the original drive.
  • Added examples to man page + some cleanup/clarification

@akuker akuker requested a review from uweseimet December 8, 2022 19:05
@akuker akuker marked this pull request as ready for review December 8, 2022 19:05

int run(const vector<char *> &);

struct inquiry_info_struct {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this struct have to be public instead of being private?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its used in the test procedure. Suggestions for a better way to make it accessible to the test procedure?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case (tests also using it) there might be no alternative. In general an implementation should not have weak points just because of unit tests. If datat structures are/should be private from the implementation perspective (like in this case) tests should be coded in a way that they do not need to access these private structures. This is best practices as far as I know, and it makes sense. Otherwise you end up with a lot of data being public just because of the tests, which is defeating the idea of encapsulation.

Copy link
Copy Markdown
Contributor

@uweseimet uweseimet Dec 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one anecdotal note on this, because I just remembered: In a job interview I had a long time ago, how to deal with a similar issue was a topic. It was essentially a private constant string that was part of the implementation. The string content was also required in a unit test. The preferred solution was to have a copy of the string (duplication) in the test, so that the original string could stay private.
In this particular case using a copy has also another benefit: If you use the same public string for your test, if somebody changes the string declaration your code may be wrong, but the test still passes. You will miss the code modification. With a copy for the test it would have been revealed that something in the code had been changed,.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case its a struct, not data. Another solution would be to move it out of the class definition completely.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't object keeping the code as it is if there is no convenient alternative.


// TODO Replace old-fashinoned C I/O by C++ streams I/O.
// This also avoids potential issues with data type sizes and there is no need for c_str().
void CreateTempFileWithData(const string& filename, vector<uint8_t> &data)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would appreciate if we were not reverting C++-style conventions for pointers and references back to C-style. We have C++ style almost everywhere now, and it's not just Bjarne Stroustrup who says:

A typical C programmer writes int *p; and explains it *p is what is the int emphasizing syntax, and may point to the C (and C++) declaration grammar to argue for the correctness of the style. Indeed, the * binds to the name p in the grammar.

A typical C++ programmer writes int* p; and explains it p is a pointer to an int emphasizing type. Indeed the type of p is int*. I clearly prefer that emphasis and see it as important for using the more advanced parts of C++ well.

but also IBM, cpppreference.com, ...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you saying that you prefer this:

void CreateTempFileWithData(const string& filename, vector<uint8_t>& data)

over this?

void CreateTempFileWithData(const string &filename, vector<uint8_t> &data)

Currently, its the clang formatting configuration that is doing this, so I'll need to investigate. But, I wanted to double check I'm understanding the comment first.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's what I (and others like Stroustrup) are saying for pointers (*) and references (&) in C++. (If you google for it you will find several hits.) When using "&" as address operator it's different, but for "&" denoting a reference it should directly follow the type.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I'll work on updating that configuration.

Copy link
Copy Markdown
Member Author

@akuker akuker Dec 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should now be updated. See changes in .clang-format. This change will be applicable to pointers and references

string ReadTempFileToString(const string &filename)
{
path temp_file = test_data_temp_path / path(filename);
std::ifstream in_fs(temp_file);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we usually declare namespace std to be used we should omit std:: for simplicity and readability sake.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.


bool restore = false;

const string divider_str = "----------------------------------------";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this string be static?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

doc/scsidump.1 Outdated
.TP
.BR \-r\fI
Run in restore mode.
Run in restore mode. Defaults to download mode if not specified.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think "download" is a good term. The common terms are dump/restore, just as the names of the respective UNIX commands. Downloading is quite specific for the file downloads in the internet.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to dump

scsidump has two modes of operation: download and restore. These can be used with physical storage media, including hard drives and magneto optical drives. Download mode can be used with read-only media such as CD/DVD drives.

Set its own ID with the BID option. Defaults to 7 if ommitted.
When operating in download mode, scsidump will copy all data from a remote SCSI drive to an image on the local filesystem. Additionally, it will generate a .properties file that can be used to more closely emulate the source drive.
Copy link
Copy Markdown
Contributor

@uweseimet uweseimet Dec 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the creation of the .properties file mandatory? It should not be because not everybody (not just not me) would want unexpected and potentially invisible (dot) files to be created.
Making the file creation optional and the filename configurable would IMO be best. One should also consider not to overwrite existing files.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now requires '-p' argument in order to enable this feature.

Copy link
Copy Markdown
Contributor

@uweseimet uweseimet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see my comments.

@uweseimet
Copy link
Copy Markdown
Contributor

uweseimet commented Dec 8, 2022

A general remark, not specific to this PR, but also concerning this PR: For functional extensions like in this case (property file) it might be good to have a ticket first because:

  • Others (not only somebody involved in the review or not even a developer) can provide useful comments
  • Changes to already implemented new code can be avoided, because the implementation goal can be adjusted before starting the implemention. This saves time because you do not implement something (at least not that often) that you later may have to change.
  • Comments in tickets IMHO are more informal than in reviews, which makes it easier to talk about changes. Once you have a PR, as a reviewer I usually do not want to block something, and requesting changes is more unpleasant than in a ticket. (At least for me.)
  • Tickets are potentially read by more developers/users than a PR, which improves the overall knowledge about a project.
  • Personally, if I were to search for something that has already been discussed in a project I would search the tickets, not the PRs.

Just my two cents.

@uweseimet
Copy link
Copy Markdown
Contributor

@akuker Thank you four addressing my comments.

@akuker
Copy link
Copy Markdown
Member Author

akuker commented Dec 9, 2022

@uweseimet - Thank you for reviewing!! I'll try to do a better job of writing up issues before implementing things

@akuker akuker merged commit 5b3626d into develop Dec 9, 2022
@akuker akuker deleted the feature_scsidump_usability branch December 9, 2022 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants