I wonder if it would make sense to move the reference counting out of libplfs and into FUSE and then just disallow *pfd in plfs_open from being non-NULL? You'd modify the FUSE open_files map to have the reference count.
That might simplify the mainline code a bit, and not complicate the FUSE much more than it currently is (since it has to manage the open filename map anyway).
I looked at this some more and I'm thinking the thread locking doesn't use the counts.
The main reference counter is Metadata::reference_count which is accessed via the incrementOpens(int amount) API. The main place that gets touched is in the open/close code path (not surprising), but if we moved the reference count up into FUSE then that code would go away.
The reference counting actually trickles up anyway... via the last arg of the plfs_close() API:
plfs_error_t plfs_close(Plfs_fd fd, pid_t pid, uid_t u, int open_flags,
Plfs_close_opt close_opt, int *num_ref)
that "num_ref" becomes "remaining" in the FUSE layer and FUSE does locking on the FUSE "struct OpenFile" ... so maybe in the current code the locking is in the FUSE layer (on OpenFile) but the reference count is down in Metadata::reference_count.
if we make this move, the "num_ref" in that API doesn't make sense anymore either. we could get rid of it, but that would change an external API.
I wonder if it would make sense to move the reference counting out of libplfs and into FUSE and then just disallow *pfd in plfs_open from being non-NULL? You'd modify the FUSE open_files map to have the reference count.
That might simplify the mainline code a bit, and not complicate the FUSE much more than it currently is (since it has to manage the open filename map anyway).
I looked at this some more and I'm thinking the thread locking doesn't use the counts.
The main reference counter is Metadata::reference_count which is accessed via the incrementOpens(int amount) API. The main place that gets touched is in the open/close code path (not surprising), but if we moved the reference count up into FUSE then that code would go away.
The reference counting actually trickles up anyway... via the last arg of the plfs_close() API:
plfs_error_t plfs_close(Plfs_fd fd, pid_t pid, uid_t u, int open_flags, Plfs_close_opt close_opt, int *num_ref)
that "num_ref" becomes "remaining" in the FUSE layer and FUSE does locking on the FUSE "struct OpenFile" ... so maybe in the current code the locking is in the FUSE layer (on OpenFile) but the reference count is down in Metadata::reference_count.
if we make this move, the "num_ref" in that API doesn't make sense anymore either. we could get rid of it, but that would change an external API.