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
39 file system striping information. The file descriptor is then accessed with
40 <literal>open()</literal>.</para>
41 <informaltable frame="all">
43 <colspec colname="c1" colwidth="50*"/>
44 <colspec colname="c2" colwidth="50*"/>
48 <para><emphasis role="bold">Option</emphasis></para>
51 <para><emphasis role="bold">Description</emphasis></para>
58 <para> <literal>llapi_file_create()</literal></para>
61 <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>
66 <para> <literal>stripe_size</literal></para>
69 <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>
74 <para> <literal>stripe_offset</literal></para>
77 <para>Indicates the starting OST for this file.</para>
82 <para> <literal>stripe_count</literal></para>
85 <para>Indicates the number of OSTs that this file will be striped across.</para>
90 <para> <literal>stripe_pattern</literal></para>
93 <para>Indicates the RAID pattern.</para>
100 <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>
104 <title>Examples</title>
105 <para>System default size is 4 MB.</para>
106 <screen>char *tfile = TESTFILE;
107 int stripe_size = 65536</screen>
108 <para>To start at default, run:</para>
109 <screen>int stripe_offset = -1</screen>
110 <para>To start at the default, run:</para>
111 <screen>int stripe_count = 1</screen>
112 <para>To set a single stripe for this example, run:</para>
113 <screen>int stripe_pattern = 0</screen>
114 <para>Currently, only RAID 0 is supported.</para>
115 <screen>int stripe_pattern = 0;
117 rc = llapi_file_create(tfile, stripe_size,stripe_offset, stripe_count,stripe_pattern);</screen>
118 <para>Result code is inverted, you may return with '<literal>EINVAL</literal>' or an ioctl error.</para>
120 fprintf(stderr,"llapi_file_create failed: %d (%s) 0, rc, strerror(-rc));return -1; }</screen>
121 <para><literal>llapi_file_create</literal> closes the file descriptor. You must re-open the descriptor. To do this, run:</para>
122 <screen>fd = open(tfile, O_CREAT | O_RDWR | O_LOV_DELAY_CREATE, 0644); if (fd < 0) \ {
123 fprintf(stderr, "Can't open %s file: %s0, tfile,
130 <section xml:id="dbdoclet.50438215_50149">
131 <title>llapi_file_get_stripe</title>
132 <para>Use <literal>llapi_file_get_stripe</literal> to get striping information for a file or directory on a Lustre file system.</para>
134 <title>Synopsis</title>
136 #include <lustre/lustreapi.h>
138 int llapi_file_get_stripe(const char *<emphasis>path</emphasis>, void *<emphasis>lum</emphasis>);</screen>
141 <title>Description</title>
142 <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>
143 <screen>struct lov_user_md_v1 {
147 __u64 lmm_object_seq;
148 __u32 lmm_stripe_size;
149 __u16 lmm_stripe_count;
150 __u16 lmm_stripe_offset;
151 struct lov_user_ost_data_v1 lmm_objects[0];
152 } __attribute__((packed));
153 struct lov_user_md_v3 {
157 __u64 lmm_object_seq;
158 __u32 lmm_stripe_size;
159 __u16 lmm_stripe_count;
160 __u16 lmm_stripe_offset;
161 char lmm_pool_name[LOV_MAXPOOLNAME];
162 struct lov_user_ost_data_v1 lmm_objects[0];
163 } __attribute__((packed));</screen>
164 <informaltable frame="all">
166 <colspec colname="c1" colwidth="50*"/>
167 <colspec colname="c2" colwidth="50*"/>
171 <para><emphasis role="bold">Option</emphasis></para>
174 <para><emphasis role="bold">Description</emphasis></para>
181 <para> <literal>lmm_magic</literal></para>
184 <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>
189 <para> <literal>lmm_pattern</literal></para>
192 <para>Holds the striping pattern. Only <literal>LOV_PATTERN_RAID0</literal> is
193 possible in this Lustre software release.</para>
198 <para> <literal>lmm_object_id</literal></para>
201 <para>Holds the MDS object ID.</para>
206 <para> <literal>lmm_object_gr</literal></para>
209 <para>Holds the MDS object group.</para>
214 <para> <literal>lmm_stripe_size</literal></para>
217 <para>Holds the stripe size in bytes.</para>
222 <para> <literal>lmm_stripe_count</literal></para>
225 <para>Holds the number of OSTs over which the file is striped.</para>
230 <para> <literal>lmm_stripe_offset</literal></para>
233 <para>Holds the OST index from which the file starts.</para>
238 <para> <literal>lmm_pool_name</literal></para>
241 <para>Holds the OST pool name to which the file belongs.</para>
246 <para> <literal>lmm_objects</literal></para>
249 <para>An array of <literal>lmm_stripe_count</literal> members containing per OST file information in</para>
250 <para>the following format:</para>
251 <screen>struct lov_user_ost_data_v1 {
256 } __attribute__((packed));</screen>
261 <para> <literal>l_object_id</literal></para>
264 <para>Holds the OST's object ID.</para>
269 <para> <literal>l_object_seq</literal></para>
272 <para>Holds the OST's object group.</para>
277 <para> <literal>l_ost_gen</literal></para>
280 <para>Holds the OST's index generation.</para>
285 <para> <literal>l_ost_idx</literal></para>
288 <para>Holds the OST's index in LOV.</para>
296 <title>Return Values</title>
297 <para><literal>llapi_file_get_stripe()</literal> returns:</para>
298 <para><literal>0</literal> On success</para>
299 <para><literal>!= 0</literal> On failure, <literal>errno</literal> is set appropriately</para>
302 <title>Errors</title>
303 <informaltable frame="all">
305 <colspec colname="c1" colwidth="50*"/>
306 <colspec colname="c2" colwidth="50*"/>
310 <para><emphasis role="bold">Errors</emphasis></para>
313 <para><emphasis role="bold">Description</emphasis></para>
320 <para> <literal>ENOMEM</literal></para>
323 <para>Failed to allocate memory</para>
328 <para> <literal>ENAMETOOLONG</literal></para>
331 <para>Path was too long</para>
336 <para> <literal>ENOENT</literal></para>
339 <para>Path does not point to a file or directory</para>
344 <para> <literal>ENOTTY</literal></para>
347 <para>Path does not point to a Lustre file system</para>
352 <para> <literal>EFAULT</literal></para>
355 <para>Memory region pointed by lum is not properly mapped</para>
363 <title>Examples</title>
365 #include <stdio.h>
366 #include <stdlib.h>
367 #include <errno.h>
368 #include <lustre/lustreapi.h>
370 static inline int maxint(int a, int b)
372 return a > b ? a : b;
374 static void *alloc_lum()
377 v1 = sizeof(struct lov_user_md_v1) +
378 LOV_MAX_STRIPE_COUNT * sizeof(struct lov_user_ost_data_v1);
379 v3 = sizeof(struct lov_user_md_v3) +
380 LOV_MAX_STRIPE_COUNT * sizeof(struct lov_user_ost_data_v1);
381 return malloc(maxint(v1, v3));
383 int main(int argc, char** argv)
385 struct lov_user_md *lum_file = NULL;
389 fprintf(stderr, "Usage: %s <filename>\n", argv[0]);
392 lum_file = alloc_lum();
393 if (lum_file == NULL) {
397 rc = llapi_file_get_stripe(argv[1], lum_file);
402 /* stripe_size stripe_count */
403 printf("%d %d\n",
404 lum_file->lmm_stripe_size,
405 lum_file->lmm_stripe_count);
407 if (lum_file != NULL)
414 <section xml:id="dbdoclet.50438215_86607">
416 <literal>llapi_file_open</literal>
418 <para>The <literal>llapi_file_open</literal> command opens (or creates) a file or device on a
419 Lustre file system.</para>
421 <title>Synopsis</title>
422 <screen>#include <lustre/lustreapi.h>
423 int llapi_file_open(const char *<emphasis>name</emphasis>, int <emphasis>flags</emphasis>, int <emphasis>mode</emphasis>,
424 unsigned long long <emphasis>stripe_size</emphasis>, int <emphasis>stripe_offset</emphasis>,
425 int <emphasis>stripe_count</emphasis>, int <emphasis>stripe_pattern</emphasis>);
426 int llapi_file_create(const char *<emphasis>name</emphasis>, unsigned long long <emphasis>stripe_size</emphasis>,
427 int <emphasis>stripe_offset</emphasis>, int <emphasis>stripe_count</emphasis>,
428 int <emphasis>stripe_pattern</emphasis>);
432 <title>Description</title>
433 <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>
434 <para><literal>llapi_file_open()</literal> opens a file with a given name on a Lustre file
436 <informaltable frame="all">
438 <colspec colname="c1" colwidth="50*"/>
439 <colspec colname="c2" colwidth="50*"/>
443 <para><emphasis role="bold">Option</emphasis></para>
446 <para><emphasis role="bold">Description</emphasis></para>
453 <para> <literal>flags</literal></para>
456 <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>
461 <para> <literal>mode</literal></para>
464 <para>Specifies the permission bits to be used for a new file when <literal>O_CREAT</literal> is used.</para>
469 <para> <literal>stripe_size</literal></para>
472 <para>Specifies stripe size (in bytes). Should be multiple of 64 KB, not exceeding 4 GB.</para>
477 <para> <literal>stripe_offset</literal></para>
480 <para>Specifies an OST index from which the file should start. The default value is -1.</para>
485 <para> <literal>stripe_count</literal></para>
488 <para>Specifies the number of OSTs to stripe the file across. The default value is -1.</para>
493 <para> <literal>stripe_pattern</literal></para>
496 <para>Specifies the striping pattern. In this release of the Lustre software, only
497 <literal>LOV_PATTERN_RAID0</literal> is available. The default value is
506 <title>Return Values</title>
507 <para><literal>llapi_file_open()</literal> and <literal>llapi_file_create()</literal> return:</para>
508 <para><literal>>=0</literal> On success, for <literal>llapi_file_open</literal> the return value is a file descriptor</para>
509 <para><literal><0</literal> On failure, the absolute value is an error code</para>
512 <title>Errors</title>
513 <informaltable frame="all">
515 <colspec colname="c1" colwidth="50*"/>
516 <colspec colname="c2" colwidth="50*"/>
520 <para><emphasis role="bold">Errors</emphasis></para>
523 <para><emphasis role="bold">Description</emphasis></para>
530 <para> <literal>EINVAL</literal></para>
533 <para><literal>stripe_size</literal> or <literal>stripe_offset</literal> or <literal>stripe_count</literal> or <literal>stripe_pattern</literal> is invalid.</para>
538 <para> <literal>EEXIST</literal></para>
541 <para>Striping information has already been set and cannot be altered; <literal>name</literal> already exists.</para>
546 <para> <literal>EALREADY</literal></para>
549 <para>Striping information has already been set and cannot be altered</para>
554 <para> <literal>ENOTTY</literal></para>
558 <literal>name</literal> may not point to a Lustre file system.</para>
566 <title>Example</title>
568 #include <stdio.h>
569 #include <lustre/lustreapi.h>
571 int main(int argc, char *argv[])
576 rc = llapi_file_create(argv[1], 1048576, 0, 2, LOV_PATTERN_RAID0);
578 fprintf(stderr, "file creation has failed, %s\n", strerror(-rc));
581 printf("%s with stripe size 1048576, striped across 2 OSTs,"
582 " has been created!\n", argv[1]);
588 <section xml:id="dbdoclet.50438215_12433">
590 <literal>llapi_quotactl</literal>
592 <para>Use <literal>llapi_quotact</literal>l to manipulate disk quotas on a Lustre file system.</para>
594 <title>Synopsis</title>
595 <screen>#include <lustre/lustreapi.h>
596 int llapi_quotactl(char" " *mnt," " struct if_quotactl" " *qctl)
603 struct obd_dqinfo qc_dqinfo;
604 struct obd_dqblk qc_dqblk;
606 struct obd_uuid obd_uuid;
609 __u64 dqb_bhardlimit;
610 __u64 dqb_bsoftlimit;
612 __u64 dqb_ihardlimit;
613 __u64 dqb_isoftlimit;
631 <title>Description</title>
632 <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>
633 <informaltable frame="all">
635 <colspec colname="c1" colwidth="50*"/>
636 <colspec colname="c2" colwidth="50*"/>
640 <para><emphasis role="bold">Option</emphasis></para>
643 <para><emphasis role="bold">Description</emphasis></para>
650 <para> <literal>LUSTRE_Q_GETQUOTA</literal></para>
653 <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>
658 <para> <literal>LUSTRE_Q_SETQUOTA</literal></para>
661 <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>
666 <para> <literal>LUSTRE_Q_GETINFO</literal></para>
669 <para>Gets information about quotas. <emphasis>qc_type</emphasis> is either
670 <literal>USRQUOTA</literal> or <literal>GRPQUOTA</literal>. On return,
671 <emphasis>dqi_igrace</emphasis> is inode grace time (in seconds),
672 <emphasis>dqi_bgrace</emphasis> is block grace time (in seconds),
673 <emphasis>dqi_flags</emphasis> is not used by the current release of the Lustre
679 <para> <literal>LUSTRE_Q_SETINFO</literal></para>
682 <para>Sets quota information (like grace times). <emphasis>qc_type</emphasis> is
683 either <literal>USRQUOTA</literal> or <literal>GRPQUOTA</literal>.
684 <emphasis>dqi_igrace</emphasis> is inode grace time (in seconds),
685 <emphasis>dqi_bgrace</emphasis> is block grace time (in seconds),
686 <emphasis>dqi_flags</emphasis> is not used by the current release of the Lustre
687 software and must be zeroed.</para>
695 <title>Return Values</title>
696 <para><literal>llapi_quotactl()</literal> returns:</para>
697 <para><literal>0</literal> On success</para>
698 <para><literal> -1 </literal> On failure and sets error number (<literal>errno</literal>) to indicate the error</para>
701 <title>Errors</title>
702 <para><literal>llapi_quotactl</literal> errors are described below.</para>
703 <informaltable frame="all">
705 <colspec colname="c1" colwidth="50*"/>
706 <colspec colname="c2" colwidth="50*"/>
710 <para><emphasis role="bold">Errors</emphasis></para>
713 <para><emphasis role="bold">Description</emphasis></para>
720 <para> <literal>EFAULT</literal></para>
723 <para><emphasis>qctl</emphasis> is invalid.</para>
728 <para> <literal>ENOSYS</literal></para>
731 <para>Kernel or Lustre modules have not been compiled with the <literal>QUOTA</literal> option.</para>
736 <para> <literal>ENOMEM</literal></para>
739 <para>Insufficient memory to complete operation.</para>
744 <para> <literal>ENOTTY</literal></para>
747 <para> <emphasis>qc_cmd</emphasis> is invalid.</para>
752 <para> <literal>EBUSY</literal></para>
755 <para>Cannot process during quotacheck.</para>
760 <para> <literal>ENOENT</literal></para>
763 <para> <emphasis>uuid</emphasis> does not correspond to OBD or <emphasis>mnt</emphasis> does not exist.</para>
768 <para> <literal>EPERM</literal></para>
771 <para>The call is privileged and the caller is not the super user.</para>
776 <para> <literal>ESRCH</literal></para>
779 <para>No disk quota is found for the indicated user. Quotas have not been turned on for this file system.</para>
787 <section xml:id="dbdoclet.50438215_15718">
789 <literal>llapi_path2fid</literal>
791 <para>Use <literal>llapi_path2fid</literal> to get the FID from the pathname.</para>
793 <title>Synopsis</title>
794 <screen>#include <lustre/lustreapi.h>
796 int llapi_path2fid(const char *path, unsigned long long *seq, unsigned long *oid, unsigned long *ver)</screen>
799 <title>Description</title>
800 <para>The <literal>llapi_path2fid</literal> function returns the FID (sequence : object ID : version) for the pathname.</para>
803 <title>Return Values</title>
804 <para><literal>llapi_path2fid</literal> returns:</para>
805 <para><literal>0</literal> On success</para>
806 <para>non-zero value On failure</para>
809 <section condition="l29">
811 <literal>llapi_ladvise</literal>
813 <para>Use <literal>llapi_ladvise</literal> to give IO advice/hints on a
814 Lustre file to the server.</para>
816 <title>Synopsis</title>
818 #include <lustre/lustreapi.h>
819 int llapi_ladvise(int fd, unsigned long long flags,
820 int num_advise, struct llapi_lu_ladvise *ladvise);
822 struct llapi_lu_ladvise {
823 __u16 lla_advice; /* advice type */
824 __u16 lla_value1; /* values for different advice types */
826 __u64 lla_start; /* first byte of extent for advice */
827 __u64 lla_end; /* last byte of extent for advice */
834 <title>Description</title>
835 <para>The <literal>llapi_ladvise</literal> function passes an array of
836 <emphasis>num_advise</emphasis> I/O hints (up to a maximum of
837 <emphasis>LAH_COUNT_MAX</emphasis> items) in ladvise for the file
838 descriptor <emphasis>fd</emphasis> from an application to one or more
839 Lustre servers. Optionally, <emphasis>flags</emphasis> can modify how
840 the advice will be processed via bitwise-or'd values:</para>
843 <para><literal>LF_ASYNC</literal>: Clients return to userspace
844 immediately after submitting ladvise RPCs, leaving server threads to
845 handle the advices asynchronously.</para>
848 <para><literal>LF_UNSET</literal>: Unset/clear a previous advice
849 (Currently only supports LU_ADVISE_LOCKNOEXPAND).</para>
852 <para>Each of the <emphasis>ladvise</emphasis> elements is an
853 <emphasis>llapi_lu_ladvise</emphasis> structure, which contains the
855 <informaltable frame="all">
857 <colspec colname="c1" colwidth="50*"/>
858 <colspec colname="c2" colwidth="50*"/>
862 <para><emphasis role="bold">Field</emphasis></para>
865 <para><emphasis role="bold">Description</emphasis></para>
872 <para> <literal>lla_ladvice</literal></para>
875 <para>Specifies the advice for the given file range, currently
877 <para><literal>LU_LADVISE_WILLREAD</literal>: Prefetch data
878 into server cache using optimum I/O size for the server.</para>
879 <para><literal>LU_LADVISE_DONTNEED</literal>: Clean cached data
880 for the specified file range(s) on the server.</para>
885 <para> <literal>lla_start</literal></para>
888 <para>The offset in bytes for the start of this advice.</para>
893 <para> <literal>lla_end</literal></para>
896 <para>The offset in bytes (non-inclusive) for the end of this
902 <para> <literal>lla_value1</literal></para>
903 <para> <literal>lla_value2</literal></para>
904 <para> <literal>lla_value3</literal></para>
905 <para> <literal>lla_value4</literal></para>
908 <para>Additional arguments for future advice types and
909 should be set to zero if not explicitly required for a given
910 advice type. Advice-specific names for these fields
916 <para> <literal>lla_lockahead_mode</literal></para>
919 <para>When using LU_ADVISE_LOCKAHEAD, the 'lla_value1' field
920 is used to communicate the requested lock mode, and can be
921 referred to as lla_lockahead_mode.</para>
926 <para> <literal>lla_peradvice_flags</literal></para>
929 <para>When using advices which support them, the 'lla_value2'
930 field is used to communicate per-advice flags and can be
931 referred to as 'lla_peradvice_flags'. Both LF_ASYNC and
932 LF_UNSET are supported as peradvice flags.</para>
937 <para> <literal>lla_lockahead_result</literal></para>
940 <para>When using LU_ADVISE_LOCKAHEAD, the 'lla_value3' field
941 is used to communicate the result of the request, and can be
942 referred to as lla_lockahead_result.</para>
949 <para><literal>llapi_ladvise()</literal> forwards the advice to Lustre
950 servers without guaranteeing how and when servers will react to the
951 advice. Actions may or may not be triggered when the advices are
952 received, depending on the type of the advice as well as the real-time
953 decision of the affected server-side components.
955 <para> A typical usage of <literal>llapi_ladvise()</literal> is to
956 enable applications and users (via <literal>lfs ladvise</literal>)
957 with external knowledge about application I/O patterns to intervene in
958 server-side I/O handling. For example, if a group of different clients
959 are doing small random reads of a file, prefetching pages into OSS
960 cache with big linear reads before the random IO is an overall net
961 benefit. Fetching that data into each client cache with
962 <emphasis>fadvise()</emphasis> may not be beneficial, due to much more
963 data being sent to the clients.
966 LU_LADVISE_LOCKAHEAD merits a special comment. While it is possible
967 and encouraged to use it directly in your application to avoid lock
968 contention (primarily for writing to a single file from multiple
969 clients), it will also be available in the MPI-I/O / MPICH library
970 from ANL for use with the i/o aggregation mode of that library. This
971 is intended (eventually) to be the primary way this feature is used.
974 At the time of writing, this support is proposed as a patch but is
975 not yet merged in to the public ANL code base. Users are encouraged
976 to check their MPICH documentation and/or check with their library
977 provider about support.
979 <para>While conceptually similar to the
980 <emphasis>posix_fadvise</emphasis> and Linux
981 <emphasis>fadvise</emphasis> system calls, the main difference of
982 <literal>llapi_ladvise()</literal> is that
983 <emphasis>fadvise() / posix_fadvise()</emphasis> are client side
984 mechanisms that do not pass advice to the filesystem, while
985 <literal>llapi_ladvise()</literal> sends advice or hints to one or
986 more Lustre servers on which the file is stored. In some cases it may
987 be desirable to use both interfaces.
991 <title>Return Values</title>
992 <para><literal>llapi_ladvise</literal> returns:</para>
993 <para><literal>0</literal> On success</para>
994 <para><literal>-1</literal> if an error occurred (in which case, errno
995 is set appropriately).</para>
998 <title>Errors</title>
1000 <informaltable frame="all">
1002 <colspec colname="c1" colwidth="50*"/>
1003 <colspec colname="c2" colwidth="50*"/>
1007 <para><emphasis role="bold">Error</emphasis></para>
1010 <para><emphasis role="bold">Description</emphasis></para>
1017 <para> <literal>ENOMEM</literal></para>
1020 <para>Insufficient memory to complete operation.</para>
1025 <para> <literal>EINVAL</literal></para>
1028 <para>One or more invalid arguments are given.</para>
1033 <para> <literal>EFAULT</literal></para>
1036 <para>Memory region pointed by
1037 <literal>ladvise</literal> is not properly mapped.
1043 <para> <literal>ENOTSUPP</literal></para>
1046 <para>Advice type is not supported.</para>
1055 <section xml:id="dbdoclet.50438215_marker-1297700">
1056 <title>Example Using the <literal>llapi</literal> Library</title>
1057 <para>Use <literal>llapi_file_create</literal> to set Lustre software properties for a new file.
1058 For a synopsis and description of <literal>llapi_file_create</literal> and examples of how to
1059 use it, see <xref linkend="configurationfilesmoduleparameters"/>.</para>
1060 <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>
1061 <para><emphasis role="bold">A simple C program to demonstrate striping API - libtest.c</emphasis></para>
1063 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
1064 * vim:expandtab:shiftwidth=8:tabstop=8:
1066 * lustredemo - a simple example of lustreapi functions
1068 #include <stdio.h>
1069 #include <fcntl.h>
1070 #include <dirent.h>
1071 #include <errno.h>
1072 #include <stdlib.h>
1073 #include <lustre/lustreapi.h>
1074 #define MAX_OSTS 1024
1075 #define LOV_EA_SIZE(lum, num) (sizeof(*lum) + num * sizeof(*lum->lmm_objects))
1076 #define LOV_EA_MAX(lum) LOV_EA_SIZE(lum, MAX_OSTS)
1079 * This program provides crude examples of using the lustreapi API functions
1081 /* Change these definitions to suit */
1083 #define TESTDIR "/tmp" /* Results directory */
1084 #define TESTFILE "lustre_dummy" /* Name for the file we create/destroy */
1085 #define FILESIZE 262144 /* Size of the file in words */
1086 #define DUMWORD "DEADBEEF" /* Dummy word used to fill files */
1087 #define MY_STRIPE_WIDTH 2 /* Set this to the number of OST required */
1088 #define MY_LUSTRE_DIR "/mnt/lustre/ftest"
1090 int close_file(int fd)
1092 if (close(fd) < 0) {
1093 fprintf(stderr, "File close failed: %d (%s)\n", errno, strerror(errno));
1099 int write_file(int fd)
1101 char *stng = DUMWORD;
1104 for( cnt = 0; cnt < FILESIZE; cnt++) {
1105 write(fd, stng, sizeof(stng));
1109 /* Open a file, set a specific stripe count, size and starting OST
1110 * Adjust the parameters to suit */
1111 int open_stripe_file()
1113 char *tfile = TESTFILE;
1114 int stripe_size = 65536; /* System default is 4M */
1115 int stripe_offset = -1; /* Start at default */
1116 int stripe_count = MY_STRIPE_WIDTH; /*Single stripe for this demo*/
1117 int stripe_pattern = 0; /* only RAID 0 at this time */
1120 rc = llapi_file_create(tfile,
1121 stripe_size,stripe_offset,stripe_count,stripe_pattern);
1122 /* result code is inverted, we may return -EINVAL or an ioctl error.
1123 * We borrow an error message from sanity.c
1126 fprintf(stderr,"llapi_file_create failed: %d (%s) \n", rc, strerror(-rc));
1129 /* llapi_file_create closes the file descriptor, we must re-open */
1130 fd = open(tfile, O_CREAT | O_RDWR | O_LOV_DELAY_CREATE, 0644);
1132 fprintf(stderr, "Can't open %s file: %d (%s)\n", tfile, errno, strerror(errno));
1138 /* output a list of uuids for this file */
1139 int get_my_uuids(int fd)
1141 struct obd_uuid uuids[1024], *uuidp; /* Output var */
1142 int obdcount = 1024;
1145 rc = llapi_lov_get_uuids(fd, uuids, &obdcount);
1147 fprintf(stderr, "get uuids failed: %d (%s)\n",errno, strerror(errno));
1149 printf("This file system has %d obds\n", obdcount);
1150 for (i = 0, uuidp = uuids; i < obdcount; i++, uuidp++) {
1151 printf("UUID %d is %s\n",i, uuidp->uuid);
1156 /* Print out some LOV attributes. List our objects */
1157 int get_file_info(char *path)
1160 struct lov_user_md *lump;
1164 lump = malloc(LOV_EA_MAX(lump));
1169 rc = llapi_file_get_stripe(path, lump);
1172 fprintf(stderr, "get_stripe failed: %d (%s)\n",errno, strerror(errno));
1176 printf("Lov magic %u\n", lump->lmm_magic);
1177 printf("Lov pattern %u\n", lump->lmm_pattern);
1178 printf("Lov object id %llu\n", lump->lmm_object_id);
1179 printf("Lov stripe size %u\n", lump->lmm_stripe_size);
1180 printf("Lov stripe count %hu\n", lump->lmm_stripe_count);
1181 printf("Lov stripe offset %u\n", lump->lmm_stripe_offset);
1182 for (i = 0; i < lump->lmm_stripe_count; i++) {
1183 printf("Object index %d Objid %llu\n", lump->lmm_objects[i].l_ost_idx, lump->lmm_objects[i].l_object_id);
1191 /* Ping all OSTs that belong to this filesystem */
1199 sprintf(osc_dir, "/proc/fs/lustre/osc");
1200 dir = opendir(osc_dir);
1202 printf("Can't open dir\n");
1205 while((d = readdir(dir)) != NULL) {
1206 if ( d->d_type == DT_DIR ) {
1207 if (! strncmp(d->d_name, "OSC", 3)) {
1208 printf("Pinging OSC %s ", d->d_name);
1209 rc = llapi_ping("osc", d->d_name);
1211 printf(" bad\n");
1213 printf(" good\n");
1229 sprintf(filename, "%s/%s",MY_LUSTRE_DIR, TESTFILE);
1231 printf("Open a file with striping\n");
1232 file = open_stripe_file();
1233 if ( file < 0 ) {
1234 printf("Exiting\n");
1237 printf("Getting uuid list\n");
1238 rc = get_my_uuids(file);
1239 printf("Write to the file\n");
1240 rc = write_file(file);
1241 rc = close_file(file);
1242 printf("Listing LOV data\n");
1243 rc = get_file_info(filename);
1244 printf("Ping our OSTs\n");
1247 /* the results should match lfs getstripe */
1248 printf("Confirming our results with lfs getstripe\n");
1249 sprintf(sys_cmd, "/usr/bin/lfs getstripe %s/%s", MY_LUSTRE_DIR, TESTFILE);
1252 printf("All done\n");
1256 <para><emphasis role="bold">Makefile for sample application:</emphasis></para>
1258 gcc -g -O2 -Wall -o lustredemo libtest.c -llustreapi
1260 rm -f core lustredemo *.o
1263 rm -f /mnt/lustre/ftest/lustredemo
1264 rm -f /mnt/lustre/ftest/lustre_dummy
1265 cp lustredemo /mnt/lustre/ftest/
1267 <section remap="h5">
1268 <title>See Also</title>
1272 <xref linkend="dbdoclet.50438215_30970"/>
1277 <xref linkend="dbdoclet.50438215_50149"/>
1282 <xref linkend="dbdoclet.50438215_86607"/>
1287 <xref linkend="dbdoclet.50438215_12433"/>