Lock a host in a cluster

Locking a host prevents a host from being selected by the master LIM for task or job placement.

Locking a host is useful for managing your resources:

  • You can isolate machines in your cluster and apply their resources to particular work.

  • If machine owners want private control over their machines, you can allow this indefinitely or for a period of time that you choose.

  • Hosts can be unlocked automatically or unlocked manually.

To lock a host, use ls_lockhost():

int ls_lockhost(time_t duration)

ls_lockhost()has the following parameter:

  • time_t duration: The number of seconds the host is locked

  1. To lock a host indefinitely, assign 0 seconds to duration.
  2. To automatically unlock a host, assign a value greater than 0 to duration and the host will automatically unlock when time has expired.
Note:

If you try to lock a host that is already locked, ls_lockhost()sets lserrno to LSE_LIM_ALOCKED.

Example

The following code example demonstrates how to use ls_lockhost() to lock a host:

/****************************************************** 
* LSLIB -- Examples 
* 
* ls_lockhost() 
* Locks the local host for a specified time. 
******************************************************/
#include <lsf/lsf.h> 
#include <time.h>
int main(int argc, char ** argv)
{ 
/* Declaring variables*/ 
   u_long duration;
/* Checking for the correct format */ 
   if (argc !=2) 
{ 
     fprintf(stderr, "usage: sudo %s <duration>\n", argv[0]); 
     exit(-1); 
}
/* assigning the duration of the lockage*/ 
   duration = atoi(argv[1]);
/* If an error occurs, exit with an error msg*/ 
   if (ls_lockhost(duration) !=0) 
{ 
     ls_perror("ls_lockhost"); 
     exit(-1); 
}
/* If ls_lockhost() is successful, then check to see if duration is > 0. Indicate how long the host is locked if duration is >0 */
   if (duration > 0) 
{ 
     printf("Host is locked for %i seconds \n", (int)              duration); 
} 
   else /* Indicate indefinite lock on host */ 
{ 
    printf("Host is locked\n");
}
/* successful exit */ 
exit(0); 
}