1 <?xml version='1.0' encoding='UTF-8'?><chapter xmlns="http://docbook.org/ns/docbook" xmlns:xl="http://www.w3.org/1999/xlink" version="5.0" xml:lang="en-US" xml:id="settinglustreproperties">
2 <title xml:id="settinglustreproperties.title">Setting Lustre Properties in a C Program (<literal>llapi</literal>)</title>
3 <para>This chapter describes the <literal>llapi</literal> library of commands used for setting Lustre file properties within a C program running in a cluster environment, such as a data processing or MPI application. The commands described in this chapter are:</para>
6 <para><xref linkend="dbdoclet.50438215_30970"/></para>
9 <para><xref linkend="dbdoclet.50438215_50149"/></para>
12 <para><xref linkend="dbdoclet.50438215_86607"/></para>
15 <para><xref linkend="dbdoclet.50438215_12433"/></para>
18 <para><xref linkend="dbdoclet.50438215_15718"/></para>
22 <para>Lustre programming interface man pages are found in the <literal>lustre/doc</literal> folder.</para>
24 <section xml:id="dbdoclet.50438215_30970">
26 <literal>llapi_file_create</literal>
28 <para>Use <literal>llapi_file_create</literal> to set Lustre properties for a new file.</para>
30 <title>Synopsis</title>
31 <screen>#include <lustre/lustreapi.h>
33 int llapi_file_create(char *name, long stripe_size, int stripe_offset, int stripe_count, int stripe_pattern);
37 <title>Description</title>
38 <para>The <literal>llapi_file_create()</literal> function sets a file descriptor's Lustre striping information. The file descriptor is then accessed with <literal>open()</literal>.</para>
39 <informaltable frame="all">
41 <colspec colname="c1" colwidth="50*"/>
42 <colspec colname="c2" colwidth="50*"/>
46 <para><emphasis role="bold">Option</emphasis></para>
49 <para><emphasis role="bold">Description</emphasis></para>
56 <para> <literal>llapi_file_create()</literal></para>
59 <para>If the file already exists, this parameter returns to '<literal>EEXIST</literal>'. If the stripe parameters are invalid, this parameter returns to '<literal>EINVAL</literal>'.</para>
64 <para> <literal>stripe_size</literal></para>
67 <para>This value must be an even multiple of system page size, as shown by <literal>getpagesize()</literal>. The default Lustre stripe size is 4MB.</para>
72 <para> <literal>stripe_offset</literal></para>
75 <para>Indicates the starting OST for this file.</para>
80 <para> <literal>stripe_count</literal></para>
83 <para>Indicates the number of OSTs that this file will be striped across.</para>
88 <para> <literal>stripe_pattern</literal></para>
91 <para>Indicates the RAID pattern.</para>
98 <para>Currently, only RAID 0 is supported. To use the system defaults, set these values: <literal>stripe_size</literal> = 0, <literal>stripe_offset</literal> = -1, <literal>stripe_count</literal> = 0, <literal>stripe_pattern</literal> = 0</para>
102 <title>Examples</title>
103 <para>System default size is 4 MB.</para>
104 <screen>char *tfile = TESTFILE;
105 int stripe_size = 65536</screen>
106 <para>To start at default, run:</para>
107 <screen>int stripe_offset = -1</screen>
108 <para>To start at the default, run:</para>
109 <screen>int stripe_count = 1</screen>
110 <para>To set a single stripe for this example, run:</para>
111 <screen>int stripe_pattern = 0</screen>
112 <para>Currently, only RAID 0 is supported.</para>
113 <screen>int stripe_pattern = 0;
115 rc = llapi_file_create(tfile, stripe_size,stripe_offset, stripe_count,stripe_pattern);</screen>
116 <para>Result code is inverted, you may return with '<literal>EINVAL</literal>' or an ioctl error.</para>
118 fprintf(stderr,"llapi_file_create failed: %d (%s) 0, rc, strerror(-rc));return -1; }</screen>
119 <para><literal>llapi_file_create</literal> closes the file descriptor. You must re-open the descriptor. To do this, run:</para>
120 <screen>fd = open(tfile, O_CREAT | O_RDWR | O_LOV_DELAY_CREATE, 0644); if (fd < 0) \ {
121 fprintf(stderr, "Can't open %s file: %s0, tfile,
128 <section xml:id="dbdoclet.50438215_50149">
129 <title>llapi_file_get_stripe</title>
130 <para>Use <literal>llapi_file_get_stripe</literal> to get striping information for a file or directory on a Lustre file system.</para>
132 <title>Synopsis</title>
134 #include <lustre/lustreapi.h>
136 int llapi_file_get_stripe(const char *<emphasis>path</emphasis>, void *<emphasis>lum</emphasis>);</screen>
139 <title>Description</title>
140 <para>The <literal>llapi_file_get_stripe()</literal> function returns striping information for a file or directory <emphasis>path</emphasis> in <emphasis>lum</emphasis> (which should point to a large enough memory region) in one of the following formats:</para>
141 <screen>struct lov_user_md_v1 {
145 __u64 lmm_object_seq;
146 __u32 lmm_stripe_size;
147 __u16 lmm_stripe_count;
148 __u16 lmm_stripe_offset;
149 struct lov_user_ost_data_v1 lmm_objects[0];
150 } __attribute__((packed));
151 struct lov_user_md_v3 {
155 __u64 lmm_object_seq;
156 __u32 lmm_stripe_size;
157 __u16 lmm_stripe_count;
158 __u16 lmm_stripe_offset;
159 char lmm_pool_name[LOV_MAXPOOLNAME];
160 struct lov_user_ost_data_v1 lmm_objects[0];
161 } __attribute__((packed));</screen>
162 <informaltable frame="all">
164 <colspec colname="c1" colwidth="50*"/>
165 <colspec colname="c2" colwidth="50*"/>
169 <para><emphasis role="bold">Option</emphasis></para>
172 <para><emphasis role="bold">Description</emphasis></para>
179 <para> <literal>lmm_magic</literal></para>
182 <para>Specifies the format of the returned striping information. <literal>LOV_MAGIC_V1</literal> is used for lov_user_md_v1. LOV_MAGIC_V3 is used for <literal>lov_user_md_v3</literal>.</para>
187 <para> <literal>lmm_pattern</literal></para>
190 <para>Holds the striping pattern. Only <literal>LOV_PATTERN_RAID0</literal> is possible in this Lustre version.</para>
195 <para> <literal>lmm_object_id</literal></para>
198 <para>Holds the MDS object ID.</para>
203 <para> <literal>lmm_object_gr</literal></para>
206 <para>Holds the MDS object group.</para>
211 <para> <literal>lmm_stripe_size</literal></para>
214 <para>Holds the stripe size in bytes.</para>
219 <para> <literal>lmm_stripe_count</literal></para>
222 <para>Holds the number of OSTs over which the file is striped.</para>
227 <para> <literal>lmm_stripe_offset</literal></para>
230 <para>Holds the OST index from which the file starts.</para>
235 <para> <literal>lmm_pool_name</literal></para>
238 <para>Holds the OST pool name to which the file belongs.</para>
243 <para> <literal>lmm_objects</literal></para>
246 <para>An array of <literal>lmm_stripe_count</literal> members containing per OST file information in</para>
247 <para>the following format:</para>
248 <screen>struct lov_user_ost_data_v1 {
253 } __attribute__((packed));</screen>
258 <para> <literal>l_object_id</literal></para>
261 <para>Holds the OST's object ID.</para>
266 <para> <literal>l_object_seq</literal></para>
269 <para>Holds the OST's object group.</para>
274 <para> <literal>l_ost_gen</literal></para>
277 <para>Holds the OST's index generation.</para>
282 <para> <literal>l_ost_idx</literal></para>
285 <para>Holds the OST's index in LOV.</para>
293 <title>Return Values</title>
294 <para><literal>llapi_file_get_stripe()</literal> returns:</para>
295 <para><literal>0</literal> On success</para>
296 <para><literal>!= 0</literal> On failure, <literal>errno</literal> is set appropriately</para>
299 <title>Errors</title>
300 <informaltable frame="all">
302 <colspec colname="c1" colwidth="50*"/>
303 <colspec colname="c2" colwidth="50*"/>
307 <para><emphasis role="bold">Errors</emphasis></para>
310 <para><emphasis role="bold">Description</emphasis></para>
317 <para> <literal>ENOMEM</literal></para>
320 <para>Failed to allocate memory</para>
325 <para> <literal>ENAMETOOLONG</literal></para>
328 <para>Path was too long</para>
333 <para> <literal>ENOENT</literal></para>
336 <para>Path does not point to a file or directory</para>
341 <para> <literal>ENOTTY</literal></para>
344 <para>Path does not point to a Lustre file system</para>
349 <para> <literal>EFAULT</literal></para>
352 <para>Memory region pointed by lum is not properly mapped</para>
360 <title>Examples</title>
362 #include <stdio.h>
363 #include <stdlib.h>
364 #include <errno.h>
365 #include <lustre/lustreapi.h>
367 static inline int maxint(int a, int b)
369 return a > b ? a : b;
371 static void *alloc_lum()
374 v1 = sizeof(struct lov_user_md_v1) +
375 LOV_MAX_STRIPE_COUNT * sizeof(struct lov_user_ost_data_v1);
376 v3 = sizeof(struct lov_user_md_v3) +
377 LOV_MAX_STRIPE_COUNT * sizeof(struct lov_user_ost_data_v1);
378 return malloc(maxint(v1, v3));
380 int main(int argc, char** argv)
382 struct lov_user_md *lum_file = NULL;
386 fprintf(stderr, "Usage: %s <filename>\n", argv[0]);
389 lum_file = alloc_lum();
390 if (lum_file == NULL) {
394 rc = llapi_file_get_stripe(argv[1], lum_file);
399 /* stripe_size stripe_count */
400 printf("%d %d\n",
401 lum_file->lmm_stripe_size,
402 lum_file->lmm_stripe_count);
404 if (lum_file != NULL)
411 <section xml:id="dbdoclet.50438215_86607">
413 <literal>llapi_file_open</literal>
415 <para>The <literal>llapi_file_open</literal> command opens (or creates) a file or device on a Lustre filesystem.</para>
417 <title>Synopsis</title>
418 <screen>#include <lustre/lustreapi.h>
419 int llapi_file_open(const char *<emphasis>name</emphasis>, int <emphasis>flags</emphasis>, int <emphasis>mode</emphasis>,
420 unsigned long long <emphasis>stripe_size</emphasis>, int <emphasis>stripe_offset</emphasis>,
421 int <emphasis>stripe_count</emphasis>, int <emphasis>stripe_pattern</emphasis>);
422 int llapi_file_create(const char *<emphasis>name</emphasis>, unsigned long long <emphasis>stripe_size</emphasis>,
423 int <emphasis>stripe_offset</emphasis>, int <emphasis>stripe_count</emphasis>,
424 int <emphasis>stripe_pattern</emphasis>);
428 <title>Description</title>
429 <para>The <literal>llapi_file_create()</literal> call is equivalent to the <literal>llapi_file_open</literal> call with <emphasis>flags</emphasis> equal to <literal>O_CREAT|O_WRONLY</literal> and <emphasis>mode</emphasis> equal to <literal>0644</literal>, followed by file close.</para>
430 <para><literal>llapi_file_open()</literal> opens a file with a given name on a Lustre filesystem.</para>
431 <informaltable frame="all">
433 <colspec colname="c1" colwidth="50*"/>
434 <colspec colname="c2" colwidth="50*"/>
438 <para><emphasis role="bold">Option</emphasis></para>
441 <para><emphasis role="bold">Description</emphasis></para>
448 <para> <literal>flags</literal></para>
451 <para>Can be a combination of <literal>O_RDONLY</literal>, <literal>O_WRONLY</literal>, <literal>O_RDWR</literal>, <literal>O_CREAT</literal>, <literal>O_EXCL</literal>, <literal>O_NOCTTY</literal>, <literal>O_TRUNC</literal>, <literal>O_APPEND</literal>, <literal>O_NONBLOCK</literal>, <literal>O_SYNC</literal>, <literal>FASYNC</literal>, <literal>O_DIRECT</literal>, <literal>O_LARGEFILE</literal>, <literal>O_DIRECTORY</literal>, <literal>O_NOFOLLOW</literal>, <literal>O_NOATIME</literal>.</para>
456 <para> <literal>mode</literal></para>
459 <para>Specifies the permission bits to be used for a new file when <literal>O_CREAT</literal> is used.</para>
464 <para> <literal>stripe_size</literal></para>
467 <para>Specifies stripe size (in bytes). Should be multiple of 64 KB, not exceeding 4 GB.</para>
472 <para> <literal>stripe_offset</literal></para>
475 <para>Specifies an OST index from which the file should start. The default value is -1.</para>
480 <para> <literal>stripe_count</literal></para>
483 <para>Specifies the number of OSTs to stripe the file across. The default value is -1.</para>
488 <para> <literal>stripe_pattern</literal></para>
491 <para>Specifies the striping pattern. In this version of Lustre, only <literal>LOV_PATTERN_RAID0</literal> is available. The default value is 0.</para>
499 <title>Return Values</title>
500 <para><literal>llapi_file_open()</literal> and <literal>llapi_file_create()</literal> return:</para>
501 <para><literal>>=0</literal> On success, for <literal>llapi_file_open</literal> the return value is a file descriptor</para>
502 <para><literal><0</literal> On failure, the absolute value is an error code</para>
505 <title>Errors</title>
506 <informaltable frame="all">
508 <colspec colname="c1" colwidth="50*"/>
509 <colspec colname="c2" colwidth="50*"/>
513 <para><emphasis role="bold">Errors</emphasis></para>
516 <para><emphasis role="bold">Description</emphasis></para>
523 <para> <literal>EINVAL</literal></para>
526 <para><literal>stripe_size</literal> or <literal>stripe_offset</literal> or <literal>stripe_count</literal> or <literal>stripe_pattern</literal> is invalid.</para>
531 <para> <literal>EEXIST</literal></para>
534 <para>Striping information has already been set and cannot be altered; <literal>name</literal> already exists.</para>
539 <para> <literal>EALREADY</literal></para>
542 <para>Striping information has already been set and cannot be altered</para>
547 <para> <literal>ENOTTY</literal></para>
550 <para> <literal>name</literal> may not point to a Lustre filesystem.</para>
558 <title>Example</title>
560 #include <stdio.h>
561 #include <lustre/lustreapi.h>
563 int main(int argc, char *argv[])
568 rc = llapi_file_create(argv[1], 1048576, 0, 2, LOV_PATTERN_RAID0);
570 fprintf(stderr, "file creation has failed, %s\n", strerror(-rc));
573 printf("%s with stripe size 1048576, striped across 2 OSTs,"
574 " has been created!\n", argv[1]);
580 <section xml:id="dbdoclet.50438215_12433">
582 <literal>llapi_quotactl</literal>
584 <para>Use <literal>llapi_quotact</literal>l to manipulate disk quotas on a Lustre file system.</para>
586 <title>Synopsis</title>
587 <screen>#include <lustre/lustreapi.h>
588 int llapi_quotactl(char" " *mnt," " struct if_quotactl" " *qctl)
595 struct obd_dqinfo qc_dqinfo;
596 struct obd_dqblk qc_dqblk;
598 struct obd_uuid obd_uuid;
601 __u64 dqb_bhardlimit;
602 __u64 dqb_bsoftlimit;
604 __u64 dqb_ihardlimit;
605 __u64 dqb_isoftlimit;
623 <title>Description</title>
624 <para>The <literal>llapi_quotactl()</literal> command manipulates disk quotas on a Lustre file system mount. qc_cmd indicates a command to be applied to UID <literal>qc_id</literal> or GID <literal>qc_id</literal>.</para>
625 <informaltable frame="all">
627 <colspec colname="c1" colwidth="50*"/>
628 <colspec colname="c2" colwidth="50*"/>
632 <para><emphasis role="bold">Option</emphasis></para>
635 <para><emphasis role="bold">Description</emphasis></para>
642 <para> <literal>LUSTRE_Q_QUOTAON</literal></para>
645 <para>Turns on quotas for a Lustre file system. Deprecated as of 2.4.0. <emphasis>qc_type</emphasis> is <literal>USRQUOTA</literal>, <literal>GRPQUOTA</literal> or <literal>UGQUOTA</literal> (both user and group quota). The quota files must exist. They are normally created with the <literal>llapi_quotacheck</literal> call. This call is restricted to the super user privilege. As of 2.4.0, quota is now enabled on a per-filesystem basis via <literal>lctl conf_param</literal> (see <xref linkend="enabling_disk_quotas"/>) on the MGS node and quotacheck isn't needed any more.</para>
650 <para> <literal>LUSTRE_Q_QUOTAOFF</literal></para>
653 <para>Turns off quotas for a Lustre file system. Deprecated as of 2.4.0. <emphasis>qc_type</emphasis> is <literal>USRQUOTA</literal>, <literal>GRPQUOTA</literal> or <literal>UGQUOTA</literal> (both user and group quota). This call is restricted to the super user privilege. As of 2.4.0, quota is disabled via <literal>lctl conf_param</literal> (see <xref linkend="enabling_disk_quotas"/>).</para>
658 <para> <literal>LUSTRE_Q_GETQUOTA</literal></para>
661 <para>Gets disk quota limits and current usage for user or group <emphasis>qc_id</emphasis>. <emphasis>qc_type</emphasis> is <literal>USRQUOTA</literal> or <literal>GRPQUOTA</literal>. <emphasis>uuid</emphasis> may be filled with <literal>OBD UUID</literal> string to query quota information from a specific node. <emphasis>dqb_valid</emphasis> may be set nonzero to query information only from MDS. If <emphasis>uuid</emphasis> is an empty string and <emphasis>dqb_valid</emphasis> is zero then cluster-wide limits and usage are returned. On return, <emphasis>obd_dqblk</emphasis> contains the requested information (block limits unit is kilobyte). Quotas must be turned on before using this command.</para>
666 <para> <literal>LUSTRE_Q_SETQUOTA</literal></para>
669 <para>Sets disk quota limits for user or group <emphasis>qc_id</emphasis>. <emphasis>qc_type</emphasis> is <literal>USRQUOTA</literal> or <literal>GRPQUOTA</literal>. <emphasis>dqb_valid</emphasis> must be set to <literal>QIF_ILIMITS</literal>, <literal>QIF_BLIMITS</literal> or <literal>QIF_LIMITS</literal> (both inode limits and block limits) dependent on updating limits. <emphasis>obd_dqblk</emphasis> must be filled with limits values (as set in <emphasis>dqb_valid</emphasis>, block limits unit is kilobyte). Quotas must be turned on before using this command.</para>
674 <para> <literal>LUSTRE_Q_GETINFO</literal></para>
677 <para>Gets information about quotas. <emphasis>qc_type</emphasis> is either <literal>USRQUOTA</literal> or <literal>GRPQUOTA</literal>. On return, <emphasis>dqi_igrace</emphasis> is inode grace time (in seconds), <emphasis>dqi_bgrace</emphasis> is block grace time (in seconds), <emphasis>dqi_flags</emphasis> is not used by the current Lustre version.</para>
682 <para> <literal>LUSTRE_Q_SETINFO</literal></para>
685 <para>Sets quota information (like grace times). <emphasis>qc_type</emphasis> is either <literal>USRQUOTA</literal> or <literal>GRPQUOTA</literal>. <emphasis>dqi_igrace</emphasis> is inode grace time (in seconds), <emphasis>dqi_bgrace</emphasis> is block grace time (in seconds), <emphasis>dqi_flags</emphasis> is not used by the current Lustre version and must be zeroed.</para>
693 <title>Return Values</title>
694 <para><literal>llapi_quotactl()</literal> returns:</para>
695 <para><literal>0</literal> On success</para>
696 <para><literal> -1 </literal> On failure and sets error number (<literal>errno</literal>) to indicate the error</para>
699 <title>Errors</title>
700 <para><literal>llapi_quotactl</literal> errors are described below.</para>
701 <informaltable frame="all">
703 <colspec colname="c1" colwidth="50*"/>
704 <colspec colname="c2" colwidth="50*"/>
708 <para><emphasis role="bold">Errors</emphasis></para>
711 <para><emphasis role="bold">Description</emphasis></para>
718 <para> <literal>EFAULT</literal></para>
721 <para><emphasis>qctl</emphasis> is invalid.</para>
726 <para> <literal>ENOSYS</literal></para>
729 <para>Kernel or Lustre modules have not been compiled with the <literal>QUOTA</literal> option.</para>
734 <para> <literal>ENOMEM</literal></para>
737 <para>Insufficient memory to complete operation.</para>
742 <para> <literal>ENOTTY</literal></para>
745 <para> <emphasis>qc_cmd</emphasis> is invalid.</para>
750 <para> <literal>EBUSY</literal></para>
753 <para>Cannot process during quotacheck.</para>
758 <para> <literal>ENOENT</literal></para>
761 <para> <emphasis>uuid</emphasis> does not correspond to OBD or <emphasis>mnt</emphasis> does not exist.</para>
766 <para> <literal>EPERM</literal></para>
769 <para>The call is privileged and the caller is not the super user.</para>
774 <para> <literal>ESRCH</literal></para>
777 <para>No disk quota is found for the indicated user. Quotas have not been turned on for this file system.</para>
785 <section xml:id="dbdoclet.50438215_15718">
787 <literal>llapi_path2fid</literal>
789 <para>Use <literal>llapi_path2fid</literal> to get the FID from the pathname.</para>
791 <title>Synopsis</title>
792 <screen>#include <lustre/lustreapi.h>
794 int llapi_path2fid(const char *path, unsigned long long *seq, unsigned long *oid, unsigned long *ver)</screen>
797 <title>Description</title>
798 <para>The <literal>llapi_path2fid</literal> function returns the FID (sequence : object ID : version) for the pathname.</para>
801 <title>Return Values</title>
802 <para><literal>llapi_path2fid</literal> returns:</para>
803 <para><literal>0</literal> On success</para>
804 <para>non-zero value On failure</para>
807 <section xml:id="dbdoclet.50438215_marker-1297700">
808 <title>Example Using the <literal>llapi</literal> Library</title>
809 <para>Use <literal>llapi_file_create</literal> to set Lustre properties for a new file. For a synopsis and description of llapi_file_create and examples of how to use it, see <xref linkend="configurationfilesmoduleparameters"/>.</para>
810 <para>You can set striping from inside programs like <literal>ioctl</literal>. To compile the sample program, you need to install the Lustre client source RPM.</para>
811 <para><emphasis role="bold">A simple C program to demonstrate striping API - libtest.c</emphasis></para>
813 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
814 * vim:expandtab:shiftwidth=8:tabstop=8:
816 * lustredemo - a simple example of lustreapi functions
818 #include <stdio.h>
819 #include <fcntl.h>
820 #include <dirent.h>
821 #include <errno.h>
822 #include <stdlib.h>
823 #include <lustre/lustreapi.h>
824 #define MAX_OSTS 1024
825 #define LOV_EA_SIZE(lum, num) (sizeof(*lum) + num * sizeof(*lum->lmm_objects))
826 #define LOV_EA_MAX(lum) LOV_EA_SIZE(lum, MAX_OSTS)
829 * This program provides crude examples of using the lustreapi API functions
831 /* Change these definitions to suit */
833 #define TESTDIR "/tmp" /* Results directory */
834 #define TESTFILE "lustre_dummy" /* Name for the file we create/destroy */
835 #define FILESIZE 262144 /* Size of the file in words */
836 #define DUMWORD "DEADBEEF" /* Dummy word used to fill files */
837 #define MY_STRIPE_WIDTH 2 /* Set this to the number of OST required */
838 #define MY_LUSTRE_DIR "/mnt/lustre/ftest"
840 int close_file(int fd)
842 if (close(fd) < 0) {
843 fprintf(stderr, "File close failed: %d (%s)\n", errno, strerror(errno));
849 int write_file(int fd)
851 char *stng = DUMWORD;
854 for( cnt = 0; cnt < FILESIZE; cnt++) {
855 write(fd, stng, sizeof(stng));
859 /* Open a file, set a specific stripe count, size and starting OST
860 * Adjust the parameters to suit */
861 int open_stripe_file()
863 char *tfile = TESTFILE;
864 int stripe_size = 65536; /* System default is 4M */
865 int stripe_offset = -1; /* Start at default */
866 int stripe_count = MY_STRIPE_WIDTH; /*Single stripe for this demo*/
867 int stripe_pattern = 0; /* only RAID 0 at this time */
870 rc = llapi_file_create(tfile,
871 stripe_size,stripe_offset,stripe_count,stripe_pattern);
872 /* result code is inverted, we may return -EINVAL or an ioctl error.
873 * We borrow an error message from sanity.c
876 fprintf(stderr,"llapi_file_create failed: %d (%s) \n", rc, strerror(-rc));
879 /* llapi_file_create closes the file descriptor, we must re-open */
880 fd = open(tfile, O_CREAT | O_RDWR | O_LOV_DELAY_CREATE, 0644);
882 fprintf(stderr, "Can't open %s file: %d (%s)\n", tfile, errno, strerror(errno));
888 /* output a list of uuids for this file */
889 int get_my_uuids(int fd)
891 struct obd_uuid uuids[1024], *uuidp; /* Output var */
895 rc = llapi_lov_get_uuids(fd, uuids, &obdcount);
897 fprintf(stderr, "get uuids failed: %d (%s)\n",errno, strerror(errno));
899 printf("This file system has %d obds\n", obdcount);
900 for (i = 0, uuidp = uuids; i < obdcount; i++, uuidp++) {
901 printf("UUID %d is %s\n",i, uuidp->uuid);
906 /* Print out some LOV attributes. List our objects */
907 int get_file_info(char *path)
910 struct lov_user_md *lump;
914 lump = malloc(LOV_EA_MAX(lump));
919 rc = llapi_file_get_stripe(path, lump);
922 fprintf(stderr, "get_stripe failed: %d (%s)\n",errno, strerror(errno));
926 printf("Lov magic %u\n", lump->lmm_magic);
927 printf("Lov pattern %u\n", lump->lmm_pattern);
928 printf("Lov object id %llu\n", lump->lmm_object_id);
929 printf("Lov stripe size %u\n", lump->lmm_stripe_size);
930 printf("Lov stripe count %hu\n", lump->lmm_stripe_count);
931 printf("Lov stripe offset %u\n", lump->lmm_stripe_offset);
932 for (i = 0; i < lump->lmm_stripe_count; i++) {
933 printf("Object index %d Objid %llu\n", lump->lmm_objects[i].l_ost_idx, lump->lmm_objects[i].l_object_id);
941 /* Ping all OSTs that belong to this filesystem */
949 sprintf(osc_dir, "/proc/fs/lustre/osc");
950 dir = opendir(osc_dir);
952 printf("Can't open dir\n");
955 while((d = readdir(dir)) != NULL) {
956 if ( d->d_type == DT_DIR ) {
957 if (! strncmp(d->d_name, "OSC", 3)) {
958 printf("Pinging OSC %s ", d->d_name);
959 rc = llapi_ping("osc", d->d_name);
961 printf(" bad\n");
963 printf(" good\n");
979 sprintf(filename, "%s/%s",MY_LUSTRE_DIR, TESTFILE);
981 printf("Open a file with striping\n");
982 file = open_stripe_file();
984 printf("Exiting\n");
987 printf("Getting uuid list\n");
988 rc = get_my_uuids(file);
989 printf("Write to the file\n");
990 rc = write_file(file);
991 rc = close_file(file);
992 printf("Listing LOV data\n");
993 rc = get_file_info(filename);
994 printf("Ping our OSTs\n");
997 /* the results should match lfs getstripe */
998 printf("Confirming our results with lfs getstripe\n");
999 sprintf(sys_cmd, "/usr/bin/lfs getstripe %s/%s", MY_LUSTRE_DIR, TESTFILE);
1002 printf("All done\n");
1006 <para><emphasis role="bold">Makefile for sample application:</emphasis></para>
1008 gcc -g -O2 -Wall -o lustredemo libtest.c -llustreapi
1010 rm -f core lustredemo *.o
1013 rm -f /mnt/lustre/ftest/lustredemo
1014 rm -f /mnt/lustre/ftest/lustre_dummy
1015 cp lustredemo /mnt/lustre/ftest/
1017 <section remap="h5">
1018 <title>See Also</title>
1022 <xref linkend="dbdoclet.50438215_30970"/>
1027 <xref linkend="dbdoclet.50438215_50149"/>
1032 <xref linkend="dbdoclet.50438215_86607"/>
1037 <xref linkend="dbdoclet.50438215_12433"/>