04
Mon, Nov
6 New Articles

The Rename (RENAME) MI Instruction

RPG
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

Investigate the RENAME MI instruction by experimentation.

 

In the Machine Interface Architecture Introduction documentation in the IBM i Information Center, the Object Control lock enforcement rule is described as the following:

 

Access is prohibited if another thread is holding any lock on the system object. In general, this rule applies to instructions that destroy or rename a system object.

 

You might be familiar with the "Destroy" MI instructions, such as Destroy Space (DESS), Destroy Independent Index (DESINX), and so on. However, is there an MI instruction that can be used to rename an MI object? Yes. It's the Rename (RENAME) MI instruction. This article will reveal the details of the RENAME instruction via a set of experiments.

Investigating the RENAME Instruction

A LIC trace of type MI instruction supervisor (*SVL) upon a successful Rename Object (RNMOBJ) command reveals that the QLIRNOBJ (which is the Command Processing Program (CPP) of the RNMOBJ command) issues the RENAME instruction. So let's start our investigation by tracing the RNMOBJ command. Say we have a program object named PGMA. Trace the RNMOBJ command with the Trace Internal (TRCINT) command like so:

 

4 > trcint *on trctype(*svl) job(name-of-the-current-job)

4 > rnmobj pgma *pgm pgmb

   Object PGMA in MYLIB type *PGM renamed PGMB.

4 > trcint *off

 

From the trace data collected for our previous RNMOBJ operation at V5R4M0, you might find the following MI instructions issued sequentially by program QLIRNOBJ:

 

MI SVL               IDENTIFIER : SV#00001                         TIME 14/02/21 18:02:21.374400   TDE# 000000087563

             MATTHIF       INSTRUCTION #: 6300   RETURN ADDRESS: 39BD3B308B 00945C   PROGRAM NAME: QLIRNOBJ

MI SVL               IDENTIFIER : SV#00001                        TIME 14/02/21 18:02:21.374416   TDE# 000000087563

             RSLVSP       INSTRUCTION #: 6300   RETURN ADDRESS: 39BD3B308B 003504   PROGRAM NAME: QLIRNOBJ

MI SVL               IDENTIFIER : SV#00001                         TIME 14/02/21 18:02:21.374432   TDE# 000000087563

             MATPTR       INSTRUCTION #: 6300   RETURN ADDRESS: 39BD3B308B 003634   PROGRAM NAME: QLIRNOBJ

MI SVL               IDENTIFIER : SV#00001                         TIME 14/02/21 18:02:21.374448   TDE# 000000087563

             TESTAU       INSTRUCTION #: 6300   RETURN ADDRESS: 39BD3B308B 004498   PROGRAM NAME: QLIRNOBJ

MI SVL               IDENTIFIER : SV#00001                         TIME 14/02/21 18:02:21.374448   TDE# 000000087563

             TESTAU       INSTRUCTION #: 6300   RETURN ADDRESS: 39BD3B308B 004690   PROGRAM NAME: QLIRNOBJ

MI SVL               IDENTIFIER : SV#00001                         TIME 14/02/21 18:02:21.374464   TDE# 000000087563

             LOCK         INSTRUCTION #: 6300   RETURN ADDRESS: 39BD3B308B 00613C   PROGRAM NAME: QLIRNOBJ

MI SVL               IDENTIFIER : SV#00001                         TIME 14/02/21 18:02:21.374464   TDE# 000000087563

             MATPTR       INSTRUCTION #: 6300   RETURN ADDRESS: 39BD3B308B 0061B0   PROGRAM NAME: QLIRNOBJ

MI SVL               IDENTIFIER : SV#00001                         TIME 14/02/21 18:02:21.374480   TDE# 000000087563

             RESERVED     INSTRUCTION #: 6300   RETURN ADDRESS: 24DAA86047 153CD0   PROGRAM NAME: QP0FEPFS

MI SVL               IDENTIFIER : SV#00001                         TIME 14/02/21 18:02:21.374496   TDE# 000000087563

             RENAME       INSTRUCTION #: 6300   RETURN ADDRESS: 39BD3B308B 006AF8   PROGRAM NAME: QLIRNOBJ

... ...

MI SVL              IDENTIFIER : SV#00001                         TIME 14/02/21 18:02:21.379488   TDE# 000000087563

             UNLOCK       INSTRUCTION #: 6300   RETURN ADDRESS: 39BD3B308B 00EF34   PROGRAM NAME: QLIRNOBJ

 

Determine the PowerPC instructions generated for the RENAME MI instruction in the RISC instruction stream of program QLIRNOBJ by following the RETURN ADDRESS field (39BD3B308B 006AF8 in this example) in the trace record of RENAME. The four PowerPC instructions before address 39BD3B308B 006AF8 are generated for the RENAME MI instruction, the MI instruction number of which is hex 36F in the OMI instruction stream.

 

     ADDRESS       LOCATION   OBJECT TEXT       SOURCE STATEMENT                 MI INSTRUCTION NUMBERS

39BD3B308B 006AE8     005568   389C6211         ADDI 4,28,25105                       036F

39BD3B308B 006AEC     00556C   38710000         ADDI 3,17,0

39BD3B308B 006AF0     005570   39400066         ADDI 10,0,102

39BD3B308B 006AF4     005574   44000141         SCV 10

39BD3B308B 006AF8     005578   881C2B07         LBZ 0,0X2B07(28)                     0370

 

From the RISC instructions shown above, we know that the RENAME MI instruction is implemented via a SCV 10 (Supervisor Call Vectored (SCV) with dispatch code 10) instruction with the SCV 10 function number set to 102. We also know that two operands are passed (via General Purpose Register (GPR) 3 and GPR 4) when the RENAME instruction is issued. (In the remaining part of this article, GPR N will be simply referred to as rN.) Debugging the QLIRNOBJ program shows that the operand 1 (the address of which is stored in r3) is a system pointer addressing the target MI object. For example, the 16 bytes at the address stored in r3 might look like the following (a 16-byte system pointer addressing program PGMA):

 

Address . . . . . . .   EC9E501719 0206F0

 

06F0   00000000 00000000     23DB3961 91000200 T

 

And operand 2 (the address of which is stored in r4) of RENAME might look like the following (at V5R4M0):

 

Address . . . . . . .   EC9E501719 020831

 

0830   00400000 D7C7D4C2     40404040 40404040       * . ..PGMB         *

0840   40404040 40404040     40404040 40404040       *                 *

0850   40400000 00000000     00000000 00000000       *   .............. *

Simulate the RENAME Instruction

In order to discover the detailed format of operand 2 of the RENAME instruction, we need to issue the RENAME instruction from a user program with different content in the operand 2. Given that the RENAME instruction is a blocked MI instruction, you might prefer to simulate the RENAME instruction with a non-blocked MI instruction that has similar operands to get your program complied and then modify the generated RISC instruction stream. The following tiny OMI source program, ren01.emi, accepts the symbolic ID of an MI object (object type/subtype code and object name), resolves a system pointer to it, and then simulates the RENAME instruction with the Modify Space Attributes (MODS) instruction. (The operands of the MODS instruction are of the same types as those of the RENAME instruction; operand1 is a system pointer, and operand 2 is a character scalar.)

 

dcl spcptr obj-type@ parm       ;

dcl spcptr obj-name@ parm       ;

dcl spcptr new-name@ parm       ;

dcl ol pl-main(obj-type@,

       obj-name@,

       new-name@) parm ext     ;

 

entry *(pl-main) ext           ;

 

dcl dd rt char(34) auto         ;

dcl dd obj-type char(2) bas(obj-type@) ;

dcl dd obj-name char(30) bas(obj-name@) ;

dcl dd new-name char(30) bas(new-name@) ;

 

dcl sysptr obj@ auto           ;

dcl dd tmpl char(33) auto       ;

      dcl dd opt char(1) def(tmpl) pos(1) init(x'40') ;

       dcl dd opt-2 char(1) def(tmpl) pos(2) init(x'00') ;

       dcl dd opt-3 char(1) def(tmpl) pos(3) init(x'00') ;

       dcl dd name char(30) def(tmpl) pos(4)             ;

 

       cpybrep rt, x'00'       ;

       cpybla rt(1:2), obj-type ;

       cpybla rt(3:30), obj-name ;

       rslvsp obj@, rt, *, *     ;

 

       cpybla name, new-name ;

       mods   obj@, tmpl     ;

brk     'LOOK'                 ;

       rtx     *               ;

pend                           ;

 

The PowerPC instructions generated for the MODS instruction in the compiled REN01 program are the following (at V5R4M0):

 

RISC INSTRUCTIONS (REN01)

LOCATION   OBJECT TEXT       SOURCE STATEMENT                 MI INSTRUCTION NUMBERS

   00017C   389FFFD0         ADDI 4,31,-48                         06

   000180   63630000         ORI 3,27,0

   000184   39400138         ADDI 10,0,312

   000188   44000141         SCV 10

 

Make the following changes to program REN01:

  1. Change the program state field in the program header of REN01 from user state (hex 0001) to system state (hex 0080). At V5R4M0, the program state field is at offset hex 50 from the start of the program header. Since RENAME is a blocked instruction, it is necessary for the issuing program to run in the system state at security level 40 or above.
  2. In the ADDI 10,0,312 instruction, change the immediate value copied into r10 from the SCV 10 function number of MODS2 (312) to that of the RENAME instruction (102). The changed ADDI instruction is ADDI 10,0,102 (hex 39400066).

 

Here's a quick test of our newly developed rename program:

 

4 > CRTDTAQ DTAQ(Q020) MAXLEN(5)

     Object Q020 type *DTAQ created in library MYLIB.

4 > call ren01 (x'0A01' q020 q021)

4 > rnmobj q021 *dtaq q020 /* Rename the queue obj to its original name */

     Object Q021 in MYLIB type *DTAQ renamed Q020.

4 > dltdtaq q020

     Object Q020 in MYLIB type *DTAQ deleted.

The Exact Format of Operand 2 of RENAME

To discover the format of operand 2 of the RENAME instruction, you can utilize the above-shown rename program REN01 to issue the RENAME instruction and pass different values for operand 2. Experiments show that operand 2 of RENAME is a 33-byte character scalar containing the following fields:

 

Format of Operand 2

Offset (Hex)

Field Name

Data Type and Length

0

Option

Char(1)

 

Reserved (binary 0)

Bit 0

 

Change object name

0=Do not change object name

1=Change object name

Bit 1

 

Reserved (binary 0)

Bits 2-7

1

Reserved (binary 0)

Char(2)

3

Object name

Char(30)

 

If the Change object name bit is set to zero, no change is made to the MI object specified by operand 1. If one of the reserved fields is not zero, the scalar value invalid (hex 3203) exception will be signaled.

 

Also note that the object name field can be of length up to 30 bytes, which can be proven via the following little experiment:

 

4 > CRTDTAQ DTAQ(Q020) MAXLEN(5)

     Object Q020 type *DTAQ created in library MYLIB.

4 > call ren01 (x'0A01' q020 'A *DTAQ object called Q020')

4 > call ren01 (x'0A01' 'A *DTAQ object called Q020' q020)

4 > dltdtaq q020

     Object Q020 in MYLIB type *DTAQ deleted.

 

Document the RENAME MI Instruction Based on the Experiment Results

A few other features of the RENAME instruction can be proven by some trivial experiments. For example, ren03.emi proves that RENAME can also be issued on a temporary object. Using the Edit Object Authority (EDTOBJAUT) command in combination with our previously developed rename program REN01 (or the RNMOBJ command), you can prove that the minimum authority to the object to rename is the object management authority. The fact that if any other thread holds any type of lock on an object, the rename program REN01 will fail with an invalid lock state (hex 1A01) exception proves that the lock enforcement rule applied to RENAME is enforcement of object control; in other words, a LENR (locked exclusive no read) lock state is to be enforced during the execution of the RENAME instruction. Additionally, if the new symbolic ID (object type code, subtype code, and name) is the same as an existing object in the context, a Duplicate Object Identification (hex 0E01) exception is signaled.

 

Now we are able to offer our own version of documentation (although not complete) for the RENAME instruction, which is an elementary member of the object-based high-level machine interface of IBM i and its ancestors.

 

Rename Object (RENAME)

Operand 1: System pointer

Operand 2: Char(33) scalar

 

Description: The name portion of the symbolic ID (object type code, subtype code, and name) of the system object addressed by operand 1 is optionally modified as specified by operand 2. Either permanent or temporary objects can be renamed. The object address remains unchanged after a rename operation.

 

The format of the character scalar for operand 2 is the following:

 

Format of Operand 2

Offset (Hex)

Field Name

Data Type and Length

0

Option

Char(1)

 

Reserved (binary 0)

Bit 0

 

Change object name

0=Do not change object name

1=Change object name

Bit 1

 

Reserved (binary 0)

Bits 2-7

1

Reserved (binary 0)

Char(2)

3

Object name

Char(30)

 

Authorization Required

Execute

Contexts referenced for address resolution

Object management

Operand 1

Update

Context addressing operand 1

 

Lock Enforcement

Materialize

Contexts referenced for address resolution

Modify

Context addressing operand 1

Object Control

Operand 1

 

Exceptions

0A Authorization

0A01 Unauthorized for Operation

0E Context Operation

0E01 Duplicate Object Identification

32 Scalar Specification

3203 Scalar Value Invalid

... and more

Final Thoughts

As you might have noticed, the *SVL trace of the RNMOBJ operation shows that the RNMOBJ command locks the object to rename before issuing the RENAME instruction upon it (and unlocks it after the rename operation). In my opinion, this is a reasonable design. Many operating system–level operations allocate locks on the target object. For example, a thread that opens a file (say MYFILE) for read will allocate a LSRD (locked share read) lock on the *FILE object (with MI object type/subtype code hex 1901). Therefore, an attempt to issue the RENAME instruction upon MYFILE in another thread will signal the invalid lock state (hex 1A01) exception due to the lock enforcement rules applied to RENAME. Instead, a (synchronous) lock request for LENR lock state before executing the RENAME instruction would possibly allow the user or program that issues the RNMOBJ command to wait until all existing locks allocated on the object are released by their holders. Not surprisingly, the Rename Object (QLIRNMO) API also adopts this design. For example, issue an ALCOBJ ((MYLIB/MYQUEUE *DTAQ *SHRRD)) in job A, then call the QLIRNMO API in job B like this:

 

CALL PGM(QLIRNMO) PARM(

     'MYQUEUE   MYLIB'   /* From qualified object name */

     '*DTAQ'             /* Object type */

     'YOURQUEUE MYLIB'   /* Target qualified object name */

     '0'                 /* Do not replace target object */

     X'0000000000000000' /* Error code */ )

 

So the Work with Object Locks display shown for a WRKOBJLCK MYLIB/MYQUEUE *DTAQ command might look like the following:

 

Opt   Job         User         Lock     Status         Scope     Thread

       A           LJL         *SHRRD     HELD           *JOB

       B           LJL         *EXCL     WAIT           *THREAD   00000030

 

Also note that not all object operations allocate object locks on the target object (consider program calls or queue operations).

 

Junlei Li

Junlei Li is a programmer from Tianjin, China, with 10 years of experience in software design and programming. Junlei Li began programming under i5/OS (formerly known as AS/400, iSeries) in late 2005. He is familiar with most programming languages available on i5/OS—from special-purpose languages such as OPM/ILE RPG to CL to general-purpose languages such as C, C++, Java; from strong-typed languages to script languages such as QShell and REXX. One of his favorite programming languages on i5/OS is machine interface (MI) instructions, through which one can discover some of the internal behaviors of i5/OS and some of the highlights of i5/OS in terms of operating system design.

 

Junlei Li's Web site is http://i5toolkit.sourceforge.net/, where his open-source project i5/OS Programmer's Toolkit (https://sourceforge.net/projects/i5toolkit/) is documented.

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: