fix open-write-close chatter during SendObject #128
fix open-write-close chatter during SendObject #128jfdelnero merged 5 commits intoviveris:masterfrom
Conversation
Make the fs_handles_db::fs_entry keep track of open'ed files descriptors internally. To that end the helper functions entry_open/_read/_close have been refactored to have a common signature and now manage/operate on the internal file-descriptor. Signed-off-by: Johannes Schneider <johannes.schneider@leica-geosystems.com>
Refactor the SendObject operation to deduplicate some code that is already provided by the entry_open/_close helper functions. For that only the per-use-case file open flags had to be moved, the remaining code then was the same as found in entry_open, and could be replaced by it. Signed-off-by: Johannes Schneider <johannes.schneider@leica-geosystems.com>
Remove a (now) redundant if block, shifting the enclosing code one indent left = no functional changes. Signed-off-by: Johannes Schneider <johannes.schneider@leica-geosystems.com>
Avoid multiple open-write-close operations when handling large files through the SEND_PARTIAL_OBJECT, by simply keeping the file-descriptor open, and only closing it with the finalizing END_EDIT_OBJECT operation. This avoids generating unnecessary inotify(open/modify/close) events on the OS side running the mtp-responder. Signed-off-by: Johannes Schneider <johannes.schneider@leica-geosystems.com>
|
I didn't checked the modifications yet, but have you tried to do some unexpected disconnections or similar tests to check that the file(s) are correctly closed by umtpd ? |
very good point - not yet, will do! |
When closing a session or disconnecting the gadget, have any remaining file-handles closed as well, so that in case of an aborted or otherwise interrupted transfer nothing is held open. Signed-off-by: Johannes Schneider <johannes.schneider@leica-geosystems.com>
|
your intuition was spot on: there was one line missing to cleanup/close stale file handles - added with 5a26ef1 |
The current implementation that handles
MTP_OPERATION_SEND_PARTIAL_OBJECTwould repeatedlyopen;write;closeduring a transfer of a large file.Which is undesirable when other processes in the system want to register with inotify to watch create/modify/close on a folder/file where access is provided over mtp.
The solution implemented here is to simply keep the file-descriptors around and open over the stream of
SendPartialObjectchunks.The order of MTP operations is (or seems to be, always?):
BeginEditObject,SendPartialObjectx chunk-size,EndEditObject.Now the first SendPartial would open() the file, and the trailing EndEdit would then close() it.
The first couple of commits only refactor/deduplicate/move code around - and are (intentionally) split into small parts for ease of review ;-)
The last commit is the change this PR is actually interested in.
CC @bith3ad @gujie-leica