Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for solaris FEN #196

Closed
wants to merge 4 commits into from
Closed

Conversation

gfrey
Copy link

@gfrey gfrey commented Feb 5, 2017

Fixes #12
I've signed the CLA.

What does this pull request do?

This is a basic implementation of fsnotify for Solaris FEN. It at least passes all integration tests.

Where should the reviewer start?

I used the following two resource to get a basic understanding how this should work:

How should this be manually tested?

The available integration tests are enabled for solaris now and succeed.

This is a basic implementation of fsnotify for Solaris FEN. It at least
passes all integration tests.
fen.go Outdated
var finfo C.struct_file_info
finfo.mode = C.uint(stat.Mode())

var mode C.int = C.FILE_MODIFIED | C.FILE_ATTRIB | C.FILE_NOFOLLOW

Choose a reason for hiding this comment

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

should omit type C.int from declaration of var mode; it will be inferred from the right-hand side

fen.go Outdated
}
}

func (w *Watcher) Remove(path string) error {

Choose a reason for hiding this comment

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

exported method Watcher.Remove should have comment or be unexported

fen.go Outdated
// Add starts watching the named file or directory (non-recursively).
func (w *Watcher) Add(name string) error {
return nil
func (w *Watcher) Add(path string) error {

Choose a reason for hiding this comment

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

exported method Watcher.Add should have comment or be unexported

fen.go Outdated
@@ -231,7 +231,7 @@ func (w *Watcher) associateFile(path string, stat os.FileInfo) error {
var finfo C.struct_file_info
finfo.mode = C.uint(stat.Mode())

var mode C.int = C.FILE_MODIFIED | C.FILE_ATTRIB | C.FILE_NOFOLLOW
mode := C.FILE_MODIFIED | C.FILE_ATTRIB | C.FILE_NOFOLLOW
Copy link
Author

Choose a reason for hiding this comment

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

Well type inference doesn't seem to work as houndci-bot expected. Now I need to cast the usage of mode. Not sure I like that better. Will have a closer look later.

While the `var mode C.int = ...` code isn't the nicest, at least it was
working. Type inference alone didn't work. Hopefully houndci will accept
this solution with the explicit cast.
@nathany
Copy link
Contributor

nathany commented Feb 6, 2017

@4ad @amitkris Please review.

@nathany
Copy link
Contributor

nathany commented Feb 6, 2017

@gfrey We don't currently have a good way to test Solaris, either with a CI service or locally from a different OS (I use Vagrant Gopher for Linux/BSD). Any suggestions?

@gfrey
Copy link
Author

gfrey commented Feb 7, 2017

@nathany I used VirtualBox with an OpenIndiana hipster install. I'll try and add support for solaris to your Vagrant Gopher, just give me a few days.

@nathany
Copy link
Contributor

nathany commented Feb 18, 2017

@gfrey Thanks both for this pull request and your work on Vagrant Gopher to test it.

❯ vagrant ssh solaris -c 'go version; cd fsnotify/fsnotify; go test ./...'
go version go1.8 solaris/amd64
/export/home/vagrant/src/github.com/fsnotify/fsnotify
ok      github.com/fsnotify/fsnotify    8.332s
Connection to 127.0.0.1 closed.

(unfortunately no race detector on Solaris)

I'm still hoping @4ad and/or @amitkris provide a review, but I will also take a closer look in the coming days.

@fazalmajid
Copy link

What can we do to get this PR accepted and merged into the master branch?

This is blocking getting https://github.com/spf13/hugo and https://github.com/prometheus/alertmanager (via https://github.com/stuartnelson3/guac) running on Solaris.

I confirmed that this branch merged into master works on SmartOS inside Hugo (running hugo --watch) whereas without it it just exits with the message FEN based watcher not yet supported for fsnotify. Even if gfrey's code has bugs, it can't be any more broken on Solaris than the stub in the master branch. Furthermore, fen.go is marked as +build solaris so there is zero risk of regression on other platforms.

@bep
Copy link
Member

bep commented May 22, 2017

@4ad @amitkris @nathany This would be really good for Hugo to get in. @fazalmajid has a valid point about the this cannot break it worse than it already is and the breakage is limited to Solaris. I have quickly browsed through the code and cannot find any obvious mistakes.

@tiwaana
Copy link

tiwaana commented Jun 9, 2017

We in DTC golang meetup reviewed the code, not all it. But we have few questions
a) is using C required
b) In close() things are not mutex protected.
its only limited to Solaris, so should not break other things.
Anand

@binarycrusader
Copy link

I'm not the author, but Solaris requires use of cgo, in general, since libc is the provider of system interfaces. The only other comment I would add is that this should be using golang.org/x/sys/unix instead of syscall. Per the official Go documentation, use of syscall outside of the Go standard runtime has been deprecated since 1.4:

NOTE: This package is locked down. Code outside the standard Go repository should be migrated to use the corresponding package in the golang.org/x/sys repository. That is also where updates required by new systems or versions should be applied. See https://golang.org/s/go1.4-syscall for more information.
https://golang.org/pkg/syscall/

As far as I can tell, this should work on commercial releases of Solaris, although I haven't tried it myself. It appears to be using functionality shared between Solaris and OpenSolaris-based derivatives such as Illumos/SmartOS.

@4ad
Copy link

4ad commented Jun 9, 2017

I don't care about fsnotify, so you'll have to find someone else to review this, but I will point out that using cgo here is an unnecessary mistake. This should all be done using golang.org/x/sys/unix (probably after you update it).

@quenelle
Copy link

Forgive any mistakes here, I'm very new to Go. For this kind of code there seems to be a good justification for using the C pass through interfaces. Probably lots of things don't have native Go interfaces yet. Using "syscall" is another matter. It's explicitly deprecated. I see two places where syscall is used explicitly in the code. 1) It's used to access the enumeration of errno values. When I visit x/sys/unix, it says that the official place to get errno values from is syscall.Errno. (Check the top of https://godoc.org/golang.org/x/sys/unix) So that seems legitimate. 2) The other place it's used is to access the C structure for stat_t. The code starts by using os.FileInfo, then goes through Sys() to get the stat_t. It does this because the FileInfo doesn't include atime or ctime members. (access time / create time). Only mtime (modification time) is available through FileInfo according to the docs. So I don't see any way the code could be changed to avoid the existing uses of syscall.

In theory you could argue that atime and ctime should be added FileInfo, but that seems like a change that should take into account the availability of those interfaces on other platforms. I'm not sure how widely they're supported on all the Go platforms. It doesn't seem appropriate to ask the submitter to take that on at this point.

So with that in mind, I don't see any issues with the use of cgo or syscall.

I also ran the fsnotify package test on x86 Oracle Solaris (latest internal build) with the bundled Go 1.5, and it passed. I also ran it on the same Solaris build on SPARC with the latest sparc compiler from https://github.com/4ad/go/tree/sparc64.go1.8 and it passed.

I'm not that familiar with file events in Solaris, but if additional code review is what's holding this up, I can find an Oracle Solaris engineer who is familiar with file events to check over the logic. They won't be familiar with Go, but they could vouch for the usage of Solaris interfaces.

@maxmeyer
Copy link

@dago Are you still into OpenCSW? Can their build farm help to solve the CI "problem" in this issue?

@isaacdavis
Copy link

Hi @gfrey! I work at Joyent. We maintain SmartOS, and we need fsnotify support.

Thank you for doing this work! I took a look at your pull request and made some changes. I added more robust support for cancellation to fix a race condition exhibited by the TestWatcherClose test, and I altered the interpretation of FEN events to more accurately implement fsnotify's expected behavior, as well as other small improvements.

I intend to submit a new pull request for this work. Given that my request would still substantially contain your code, how would you like to be credited? I could add you to the AUTHORS file or anything else you might prefer. Thanks!

To everyone else on this thread - I would be happy to provide additional resources for testing fsnotify on SmartOS. Please let me know!

@gfrey
Copy link
Author

gfrey commented Aug 28, 2018

@isaacdavis I'm fine with being mentioned in the AUTHORS file. Nice seeing this getting some traction again!

@dago
Copy link

dago commented Aug 28, 2018

@maxmeyer Sure. I have briefly reviewed the comments in this PR, is there something specific I should test?

@maxmeyer
Copy link

@dago What about setting about an automatic build on the opencsw build farm for this project?

@dago
Copy link

dago commented Aug 28, 2018

@maxmeyer That would be doable, we already have a number of projects in a buildbot setup which is triggered by hooks, most notable curl which has full CI integration in GitHub with different builders (click on the green checkmarks for CI build details). However, I need to update some stuff to recent Go compilers and make it compile manually first. Please PM me for details.

@maxmeyer
Copy link

@isaacdavis can you help @dago with details to make it build automatically for csw?

@isaacdavis
Copy link

@maxmeyer - Unfortunately, I'm unfamiliar with csw, and my scope of knowledge is centered on illumos/SmartOS rather than Oracle Solaris. With that said, I had no issues building fsnotify on SmartOS, so hopefully the csw build should be equally straightforward. @dago - if you run into any issues please let me know and I will try to help.

Note that I now have a new pull request open (#263) with an updated version of this code that fixes some issues. You may want to have a look!

@nathany
Copy link
Contributor

nathany commented Aug 30, 2018

Closed in favour of #263.

@nathany
Copy link
Contributor

nathany commented Aug 18, 2021

See #371

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

File Events Notifications on Solaris