nfslock01 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/bin/sh
  2. # SPDX-License-Identifier: GPL-2.0-or-later
  3. # Copyright (c) 2016-2018 Oracle and/or its affiliates. All Rights Reserved.
  4. # Copyright (c) International Business Machines Corp., 2001
  5. #
  6. # PURPOSE:
  7. # Two processes open FLOCK_IDATA file simultaneously
  8. # each one locks odd and even lines of the file simultaneously
  9. # and fill them with '0's and '1's. After they find eof, the
  10. # datafiles are compared.
  11. TST_SETUP="do_setup"
  12. TST_TESTFUNC="do_test"
  13. . nfs_lib.sh
  14. LUSER=${LUSER:=root}
  15. do_setup()
  16. {
  17. nfs_setup
  18. tst_res TINFO "creating test files"
  19. ROD nfs_flock_dgen flock_data 63 16384 0
  20. ROD nfs_flock_dgen flock_odata 63 16384 1
  21. [ "$(wc -c flock_data | awk '{print $1}')" -ne 1048576 ] && \
  22. tst_brk TBROK "could not create 'flock_data'"
  23. [ "$(wc -c flock_odata | awk '{print $1}')" -ne 1048576 ] && \
  24. tst_brk TBROK "could not create 'flock_odata'"
  25. }
  26. do_test()
  27. {
  28. tst_res TINFO "Testing locking"
  29. ROD cp flock_data flock_idata
  30. tst_res TINFO "locking 'flock_idata' file and writing data"
  31. nfs_flock 0 flock_idata &
  32. local pids=$!
  33. nfs_flock 1 flock_idata &
  34. pids="$pids $!"
  35. tst_res TINFO "waiting for pids: $pids"
  36. for p in $pids; do
  37. wait $p
  38. if [ $? -ne 0 ]; then
  39. tst_brk TFAIL "nfs_lock process failed"
  40. else
  41. tst_res TINFO "$p completed"
  42. fi
  43. done
  44. diff flock_odata flock_idata
  45. if [ $? -ne 0 ]; then
  46. tst_res TFAIL "content is different"
  47. else
  48. tst_res TPASS "content is the same"
  49. fi
  50. }
  51. tst_run