• Douglas Gilbert's avatar
    sg: O_EXCL and other lock handling · cc833acb
    Douglas Gilbert authored
    This addresses a problem reported by Vaughan Cao concerning
    the correctness of the O_EXCL logic in the sg driver. POSIX
    doesn't defined O_EXCL semantics on devices but "allow only
    one open file descriptor at a time per sg device" is a rough
    definition. The sg driver's semantics have been to wait
    on an open() when O_NONBLOCK is not given and there are
    O_EXCL headwinds. Nasty things can happen during that wait
    such as the device being detached (removed). So multiple
    locks are reworked in this patch making it large and hard
    to break down into digestible bits.
    
    This patch is against Linus's current git repository which
    doesn't include any sg patches sent in the last few weeks.
    Hence this patch touches as little as possible that it
    doesn't need to and strips out most SCSI_LOG_TIMEOUT()
    changes in v3 because Hannes said he was going to rework all
    that stuff.
    
    The sg3_utils package has several test programs written to
    test this patch. See examples/sg_tst_excl*.cpp .
    
    Not all the locks and flags in sg have been re-worked in
    this patch, notably sg_request::done . That can wait for
    a follow-up patch if this one meets with approval.
    Signed-off-by: default avatarDouglas Gilbert <dgilbert@interlog.com>
    Reviewed-by: default avatarHannes Reinecke <hare@suse.de>
    cc833acb
sg.c 71.7 KB