Pages

Wednesday, July 29, 2015

Checking for locked objects in QDLS and IFS

object lock qdls ifs dspdlonam wrkobjlck qp0fptos

In the past week one of my established jobs has started an "object locked" error. After some quick analysis I discovered that the object in question is a file in the QDLS file system. This left me asking myself a couple of questions

  1. How can I see what is locking an object in QDLS?
  2. Can I do the same for an object in the IFS?

With "standard", not QDLS and IFS, objects I can use the Work Object Locks command, WRKOBJLCK, to view what other jobs are using the object. For example:

  WRKOBJLCK OBJ(MYLIB/TESTFILE) OBJTYPE(*FILE)

For QDLS and IFS objects a different approach needs to be used. After some searching I found one method to check for object locks in QDLS, and one method for IFS (which also works for QDLS too).

 

Display object lock for QDLS objects

This approach is a two step process. The first I need to find the System Object Name of the object in the QDLS. I do this using the Display DLO Name command, DSPDLONAM command. In this example I want to see any locks on the file test.txt, which resides in the folder myqdls, therefore, the DSPDLONAM would look like:

  DSPDLONAM DLO(TEST.TXT) FLR('myqdls')

The command parameters' are not case specific, i.e. myqdls = MYQDLS = MyQdls.

                                Display DLO Name

 Document library object  . . . . . :   TEST.TXT
   Folder . . . . . . . . . . . . . :     MYQDLS

 Document identifier  . . . . . . . :   2015060211560344A54LC
 LADN timestamp . . . . . . . . . . :   07DF06020B38032C
 System object name . . . . . . . . :   DHCPH60344
 Object class . . . . . . . . . . . :   *DOC
 Auxiliary storage pool ID  . . . . :   1
   Object overflowed  . . . . . . . :     N

I record the System Object Name, DHCPH60344, and I then use the WRKOBJLCK command. The object library is QDOC and the object type is a document, *DOC.

  WRKOBJLCK OBJ(QDOC/DHCPH60344) OBJTYPE(*DOC)

 

Display object lock for IFS objects

There is not an IBM i command for checking for record locks in the IFS. I have to use an API to do so, fortunately this is one of the easier ones to use.

The QP0FPTOS (that is QP-zero-FPT-letter o-S) API is used for miscellaneous functions for the IFS. One is to display locks on objects. I only need to pass three parameters:

  1. What function I want to perform = *LSTOBJREF
  2. Object path name
  3. Report type = *FORMAT2

And the output is a spool file, QSYSPRT with the user data of QP0FDUMP.

For example, if wanted to see if the object test.txt in the folder myfolder was being used by a job I would just:

  call qp0fptos (*lstobjref '/myfolder/test.txt' *format2)

The output will be found in a QSYSPRT spool file with the user data of QP0FDUMP. In this example the object has been checked out (and locked) by the user JSMITH:

            List Object References (QP0FPTOS *LSTOBJREF *FORMAT2)
5770SS1 V7R1M0  100423
Object . . . . . . . . . . . :   /myfolder/test.txt
Use Count  . . . . . . . . . :   0
The object does have references.
Number of jobs . . . . . . . :   0
Number of jobs available . . :   0
Simple Reference Types (# of references):
   Read Only                                           0
   Write Only                                          0
   Read/Write                                          0
   Execute                                             0
   Share with Readers Only                             0
   Share with Writers Only                             0
   Share with Readers and Writers                      0
   Share with neither Readers nor Writers              0
   Attribute Lock                                      0
   Save Lock                                           0
   Internal Save Lock                                  0
   Link Changes Lock                                   0
   Checked Out                                         1
   Checked Out by SIMON
Extended Reference Types (# of job's with references):
   Read Only, Share with Readers Only                                  0
   Read Only, Share with Writers Only                                  0
   Read Only, Share with Readers and Writers                           0
   Read Only, Share with neither Readers nor Writers                   0
   Write Only, Share with Readers Only                                 0
   Write Only, Share with Writers Only                                 0
   Write Only, Share with Readers and Writers                          0
   Write Only, Share with neither Readers nor Writers                  0
   Read/Write, Share with Readers Only                                 0
   Read/Write, Share with Writers Only                                 0
   Read/Write, Share with Readers and Writers                          0
   Read/Write, Share with neither Readers nor Writers                  0
   Execute, Share with Readers Only                                    0
   Execute, Share with Writers Only                                    0
   Execute, Share with Readers and Writers                             0
   Execute, Share with neither Readers nor Writers                     0
   Execute/Read Only, Share with Readers Only                          0
   Execute/Read Only, Share with Writers Only                          0
   Execute/Read Only, Share with Readers and Writers                   0
   Execute/Read Only, Share with neither Readers nor Writers           0
   Attribute Lock                                                      0
   Save Lock                                                           0
   Internal Save Lock                                                  0
   Link Changes Lock                                                   0
   Current Directory                                                   0
   Root Directory                                                      0
   File Server Reference                                               0
   File Server Working Directory                                       0
   Checked Out                                                         1
   Checked Out by JSMITH
   NFS Server Reference                                                0
*********************** End of QP0FPTOS(*LSTOBJREF) Dump *********************

I can also use this for checking objects in the QDLS too:

  call qp0fptos (*lstobjref '/qdls/myqdls/test.txt' *format2)

 

You can learn more about this on the IBM website:

 

This article was written for IBM i 7.2, and should work for earlier releases too.

6 comments:

  1. Great article Simon!!! Thanks!!!

    ReplyDelete
  2. FYI you need *SERVICE authority to call this API.

    Chris Ringer

    ReplyDelete
  3. Thanks. Appreciated very much.
    Joe

    ReplyDelete
  4. As of IBMi 7.1 the CHKOUT and CHKIN commands were introduced.

    The CHKOUT command allows a user with the proper authority to "lock" an object in the QDLS. The object can be an individual DLO file (i.e. @dummy.csv), a wildcard (i.e. @dummy*), and a subtree.

    The CHKOUT remains in effect, and is "locked" by the user associated with the job running. The CHKOUT still remains in effect after that job ends or the user signs off.

    To unlock the object a CHKIN must be performed by a user with the appropriate authority. And yes, this means ANY user with the proper authority can CHKIN an object previously checked out by a different user. This also means a user with the proper authority can delete the object, even if it is locked.

    I user it in CLLE to make sure someone isn't locking an Excel spreadsheet before I recreate the spreadsheet.

    ReplyDelete
  5. Simon, even as of V7R5, I still don't think there is a command to check an object lock on a file in the IFS. IBM gives us this in new Nav for i .... https://www.ibm.com/support/pages/finding-jobs-having-locks-files-root-file-system-0 ..... Am I right saying there is still no WRKLNK command for this?
    Reply to michael.mayer@ermco-eci.com

    ReplyDelete

To prevent "comment spam" all comments are moderated.
Learn about this website's comments policy here.

Some people have reported that they cannot post a comment using certain computers and browsers. If this is you feel free to use the Contact Form to send me the comment and I will post it for you, please include the title of the post so I know which one to post the comment to.