1 <?xml version='1.0' encoding='UTF-8'?>
2 <!-- This document was created with Syntext Serna Free. --><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">
4 <title xml:id="settinglustreproperties.title">Setting Lustre Properties in a C Program (<literal>llapi</literal>)</title>
6 <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>
9 <para><xref linkend="dbdoclet.50438215_30970"/></para>
12 <para><xref linkend="dbdoclet.50438215_50149"/></para>
15 <para><xref linkend="dbdoclet.50438215_86607"/></para>
18 <para><xref linkend="dbdoclet.50438215_12433"/></para>
21 <para><xref linkend="dbdoclet.50438215_15718"/></para>
25 <para>Lustre programming interface man pages are found in the <literal>lustre/doc</literal> folder.</para>
27 <section xml:id="dbdoclet.50438215_30970">
28 <title>34.1 <literal>llapi_file_create</literal></title>
29 <para>Use <literal>llapi_file_create</literal> to set Lustre properties for a new file.</para>
31 <title>Synopsis</title>
32 <screen>#include <lustre/liblustreapi.h>
33 #include <lustre/lustre_user.h>
35 int llapi_file_create(char *name, long stripe_size, int stripe_offset, int stripe_count, int stripe_pattern);
39 <title>Description</title>
40 <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>
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>34.2 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>
135 <screen>#include <sys/types.h>
136 #include <sys/stat.h>
137 #include <fcntl.h>
138 #include <liblustre.h>
139 #include <lustre/lustre_idl.h>
140 #include <lustre/liblustreapi.h>
141 #include <lustre/lustre_user.h>
143 int llapi_file_get_stripe(const char *<emphasis>path</emphasis>, void *<emphasis>lum</emphasis>);</screen>
146 <title>Description</title>
147 <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>
148 <screen>struct lov_user_md_v1 {
152 __u64 lmm_object_seq;
153 __u32 lmm_stripe_size;
154 __u16 lmm_stripe_count;
155 __u16 lmm_stripe_offset;
156 struct lov_user_ost_data_v1 lmm_objects[0];
157 } __attribute__((packed));
158 struct lov_user_md_v3 {
162 __u64 lmm_object_seq;
163 __u32 lmm_stripe_size;
164 __u16 lmm_stripe_count;
165 __u16 lmm_stripe_offset;
166 char lmm_pool_name[LOV_MAXPOOLNAME];
167 struct lov_user_ost_data_v1 lmm_objects[0];
168 } __attribute__((packed));</screen>
169 <informaltable frame="all">
171 <colspec colname="c1" colwidth="50*"/>
172 <colspec colname="c2" colwidth="50*"/>
176 <para><emphasis role="bold">Option</emphasis></para>
179 <para><emphasis role="bold">Description</emphasis></para>
186 <para> <literal>lmm_magic</literal></para>
189 <para>Specifies the format of the returned striping information. <literal>LOV_MAGIC_V1</literal> isused for lov_user_md_v1. LOV_MAGIC_V3 is used for <literal>lov_user_md_v3</literal>.</para>
194 <para> <literal>lmm_pattern</literal></para>
197 <para>Holds the striping pattern. Only <literal>LOV_PATTERN_RAID0</literal> is possible in this Lustre version.</para>
202 <para> <literal>lmm_object_id</literal></para>
205 <para>Holds the MDS object ID.</para>
210 <para> <literal>lmm_object_gr</literal></para>
213 <para>Holds the MDS object group.</para>
218 <para> <literal>lmm_stripe_size</literal></para>
221 <para>Holds the stripe size in bytes.</para>
226 <para> <literal>lmm_stripe_count</literal></para>
229 <para>Holds the number of OSTs over which the file is striped.</para>
234 <para> <literal>lmm_stripe_offset</literal></para>
237 <para>Holds the OST index from which the file starts.</para>
242 <para> <literal>lmm_pool_name</literal></para>
245 <para>Holds the OST pool name to which the file belongs.</para>
250 <para> <literal>lmm_objects</literal></para>
253 <para>An array of <literal>lmm_stripe_count</literal> members containing per OST file information in</para>
254 <para>the following format:</para>
255 <screen>struct lov_user_ost_data_v1 {
260 } __attribute__((packed));</screen>
265 <para> <literal>l_object_id</literal></para>
268 <para>Holds the OST's object ID.</para>
273 <para> <literal>l_object_seq</literal></para>
276 <para>Holds the OST's object group.</para>
281 <para> <literal>l_ost_gen</literal></para>
284 <para>Holds the OST's index generation.</para>
289 <para> <literal>l_ost_idx</literal></para>
292 <para>Holds the OST's index in LOV.</para>
300 <title>Return Values</title>
301 <para><literal>llapi_file_get_stripe()</literal> returns:</para>
302 <para><literal>0</literal> On success</para>
303 <para><literal>!= 0</literal> On failure, <literal>errno</literal> is set appropriately</para>
306 <title>Errors</title>
307 <informaltable frame="all">
309 <colspec colname="c1" colwidth="50*"/>
310 <colspec colname="c2" colwidth="50*"/>
314 <para><emphasis role="bold">Errors</emphasis></para>
317 <para><emphasis role="bold">Description</emphasis></para>
324 <para> <literal>ENOMEM</literal></para>
327 <para>Failed to allocate memory</para>
332 <para> <literal>ENAMETOOLONG</literal></para>
335 <para>Path was too long</para>
340 <para> <literal>ENOENT</literal></para>
343 <para>Path does not point to a file or directory</para>
348 <para> <literal>ENOTTY</literal></para>
351 <para>Path does not point to a Lustre file system</para>
356 <para> <literal>EFAULT</literal></para>
359 <para>Memory region pointed by lum is not properly mapped</para>
367 <title>Examples</title>
368 <screen>#include <sys/vfs.h>
369 #include <liblustre.h>
370 #include <lnet/lnetctl.h>
371 #include <obd.h>
372 #include <lustre_lib.h>
373 #include <lustre/liblustreapi.h>
374 #include <obd_lov.h>
375 static inline int maxint(int a, int b)
377 return a > b ? a : b;
379 static void *alloc_lum()
382 v1 = sizeof(struct lov_user_md_v1) +
383 LOV_MAX_STRIPE_COUNT * sizeof(struct lov_user_ost_data_v1);
384 v3 = sizeof(struct lov_user_md_v3) +
385 LOV_MAX_STRIPE_COUNT * sizeof(struct lov_user_ost_data_v1);
386 return malloc(maxint(v1, v3));
388 int main(int argc, char** argv)
390 struct lov_user_md *lum_file = NULL;
394 fprintf(stderr, "Usage: %s <filename>\n", argv[0]);
397 lum_file = alloc_lum();
398 if (lum_file == NULL) {
402 rc = llapi_file_get_stripe(argv[1], lum_file);
407 /* stripe_size stripe_count */
408 printf("%d %d\n",
409 lum_file->lmm_stripe_size,
410 lum_file->lmm_stripe_count);
412 if (lum_file != NULL)
418 <section xml:id="dbdoclet.50438215_86607">
419 <title>34.3 <literal>llapi_file_open</literal></title>
420 <para>The <literal>llapi_file_open</literal> command opens (or creates) a file or device on a Lustre filesystem.</para>
422 <title>Synopsis</title>
423 <screen>#include <sys/types.h>
424 #include <sys/stat.h>
425 #include <fcntl.h>
426 #include <liblustre.h>
427 #include <lustre/lustre_idl.h>
428 #include <lustre/liblustreapi.h>
429 #include <lustre/lustre_user.h>
430 int llapi_file_open(const char *<emphasis>name</emphasis>, int <emphasis>flags</emphasis>, int <emphasis>mode</emphasis>,
431 unsigned long long <emphasis>stripe_size</emphasis>, int <emphasis>stripe_offset</emphasis>,
432 int <emphasis>stripe_count</emphasis>, int <emphasis>stripe_pattern</emphasis>);
433 int llapi_file_create(const char *<emphasis>name</emphasis>, unsigned long long <emphasis>stripe_size</emphasis>,
434 int <emphasis>stripe_offset</emphasis>, int <emphasis>stripe_count</emphasis>,
435 int <emphasis>stripe_pattern</emphasis>);
439 <title>Description</title>
440 <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>
441 <para><literal>llapi_file_open()</literal> opens a file with a given name on a Lustre filesystem.</para>
442 <informaltable frame="all">
444 <colspec colname="c1" colwidth="50*"/>
445 <colspec colname="c2" colwidth="50*"/>
449 <para><emphasis role="bold">Option</emphasis></para>
452 <para><emphasis role="bold">Description</emphasis></para>
459 <para> <literal>flags</literal></para>
462 <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>
467 <para> <literal>mode</literal></para>
470 <para>Specifies the permission bits to be used for a new file when <literal>O_CREAT</literal> is used.</para>
475 <para> <literal>stripe_size</literal></para>
478 <para>Specifies stripe size (in bytes). Should be multiple of 64 KB, not exceeding 4 GB.</para>
483 <para> <literal>stripe_offset</literal></para>
486 <para>Specifies an OST index from which the file should start. The default value is -1.</para>
491 <para> <literal>stripe_count</literal></para>
494 <para>Specifies the number of OSTs to stripe the file across. The default value is -1.</para>
499 <para> <literal>stripe_pattern</literal></para>
502 <para>Specifies the striping pattern. In this version of Lustre, only <literal>LOV_PATTERN_RAID0</literal> is available. The default value is 0.</para>
510 <title>Return Values</title>
511 <para><literal>llapi_file_open()</literal> and <literal>llapi_file_create()</literal> return:</para>
512 <para><literal>>=0</literal> On success, for <literal>llapi_file_open</literal> the return value is a file descriptor</para>
513 <para><literal><0</literal> On failure, the absolute value is an error code</para>
516 <title>Errors</title>
517 <informaltable frame="all">
519 <colspec colname="c1" colwidth="50*"/>
520 <colspec colname="c2" colwidth="50*"/>
524 <para><emphasis role="bold">Errors</emphasis></para>
527 <para><emphasis role="bold">Description</emphasis></para>
534 <para> <literal>EINVAL</literal></para>
537 <para><literal>stripe_size</literal> or <literal>stripe_offset</literal> or <literal>stripe_count</literal> or <literal>stripe_pattern</literal> is invalid.</para>
542 <para> <literal>EEXIST</literal></para>
545 <para> triping information has already been set and cannot be altered; <literal>name</literal> already exists.</para>
550 <para> <literal>EALREADY</literal></para>
553 <para>Striping information has already been set and cannot be altered</para>
558 <para> <literal>ENOTTY</literal></para>
561 <para> <literal>name</literal> may not point to a Lustre filesystem.</para>
569 <title>Example</title>
570 <screen>#include <sys/types.h>
571 #include <sys/stat.h>
572 #include <fcntl.h>
573 #include <errno.h>
574 #include <stdio.h>
575 #include <liblustre.h>
576 #include <lustre/lustre_idl.h>
577 #include <lustre/liblustreapi.h>
578 #include <lustre/lustre_user.h>
579 int main(int argc, char *argv[])
584 rc = llapi_file_create(argv[1], 1048576, 0, 2, LOV_PATTERN_RAID0);
586 fprintf(stderr, "file creation has failed, %s\n", strerror(-rc));
589 printf("%s with stripe size 1048576, striped across 2 OSTs,"
590 " has been created!\n", argv[1]);
595 <section xml:id="dbdoclet.50438215_12433">
596 <title>34.4 <literal>llapi_quotactl</literal></title>
597 <para>Use <literal>llapi_quotact</literal>l to manipulate disk quotas on a Lustre file system.</para>
599 <title>Synopsis</title>
600 <screen>#include <liblustre.h>
601 #include <lustre/lustre_idl.h>
602 #include <lustre/liblustreapi.h>
603 #include <lustre/lustre_user.h>
604 int llapi_quotactl(char" " *mnt," " struct if_quotactl" " *qctl)
611 struct obd_dqinfo qc_dqinfo;
612 struct obd_dqblk qc_dqblk;
614 struct obd_uuid obd_uuid;
617 __u64 dqb_bhardlimit;
618 __u64 dqb_bsoftlimit;
620 __u64 dqb_ihardlimit;
621 __u64 dqb_isoftlimit;
639 <title>Description</title>
640 <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>
641 <informaltable frame="all">
643 <colspec colname="c1" colwidth="50*"/>
644 <colspec colname="c2" colwidth="50*"/>
648 <para><emphasis role="bold">Option</emphasis></para>
651 <para><emphasis role="bold">Description</emphasis></para>
658 <para> <literal>LUSTRE_Q_QUOTAON</literal></para>
661 <para>Turns on quotas for a Lustre file system. <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.</para>
666 <para> <literal>LUSTRE_Q_QUOTAOFF</literal></para>
669 <para>Turns off quotas for a Lustre file system. <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.</para>
674 <para> <literal>LUSTRE_Q_GETQUOTA</literal></para>
677 <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>
682 <para> <literal>LUSTRE_Q_SETQUOTA</literal></para>
685 <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>
690 <para> <literal>LUSTRE_Q_GETINFO</literal></para>
693 <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>
698 <para> <literal>LUSTRE_Q_SETINFO</literal></para>
701 <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>
708 <section remap="h5"><title>Return Values</title><para><literal>llapi_quotactl()</literal> returns:</para><para><literal>0</literal> On success</para><para><literal>
710 </literal> On failure and sets error number (<literal>errno</literal>) to indicate the error</para></section>
712 <title>Errors</title>
713 <para><literal>llapi_quotactl</literal> errors are described below.</para>
714 <informaltable frame="all">
716 <colspec colname="c1" colwidth="50*"/>
717 <colspec colname="c2" colwidth="50*"/>
721 <para><emphasis role="bold">Errors</emphasis></para>
724 <para><emphasis role="bold">Description</emphasis></para>
731 <para> <literal>EFAULT</literal></para>
734 <para><emphasis>qctl</emphasis> is invalid.</para>
739 <para> <literal>ENOSYS</literal></para>
742 <para>Kernel or Lustre modules have not been compiled with the <literal>QUOTA</literal> option.</para>
747 <para> <literal>ENOMEM</literal></para>
750 <para>Insufficient memory to complete operation.</para>
755 <para> <literal>ENOTTY</literal></para>
758 <para> <emphasis>qc_cmd</emphasis> is invalid.</para>
763 <para> <literal>EBUSY</literal></para>
766 <para>Cannot process during quotacheck.</para>
771 <para> <literal>ENOENT</literal></para>
774 <para> <emphasis>uuid</emphasis> does not correspond to OBD or <emphasis>mnt</emphasis> does not exist.</para>
779 <para> <literal>EPERM</literal></para>
782 <para>The call is privileged and the caller is not the super user.</para>
787 <para> <literal>ESRCH</literal></para>
790 <para>No disk quota is found for the indicated user. Quotas have not been turned on for this file system.</para>
798 <section xml:id="dbdoclet.50438215_15718">
799 <title>34.5 <literal>llapi_path2fid</literal></title>
800 <para>Use <literal>llapi_path2fid</literal> to get the FID from the pathname.</para>
802 <title>Synopsis</title>
803 <screen>#include <lustre/liblustreapi.h>
804 #include <lustre/lustre_user.h>
806 int llapi_path2fid(const char *path, unsigned long long *seq, unsigned long *oid, unsigned long *ver)</screen>
809 <title>Description</title>
810 <para>The <literal>llapi_path2fid</literal> function returns the FID (sequence : object ID : version) for the pathname.</para>
813 <title>Return Values</title>
814 <para><literal>llapi_path2fid</literal> returns:</para>
815 <para><literal>0</literal> On success</para>
816 <para>non-zero value On failure</para>
819 <section xml:id="dbdoclet.50438215_marker-1297700">
820 <title>34.6 Example Using the <literal>llapi</literal> Library</title>
821 <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>
822 <para>You can set striping from inside programs like <literal>ioctl</literal>. To compile the sample program, you need to download libtest.c and liblustreapi.c files from the Lustre source tree.</para>
823 <para><emphasis role="bold">A simple C program to demonstrate striping API - libtest.c</emphasis></para>
824 <screen>/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
825 * vim:expandtab:shiftwidth=8:tabstop=8:
827 * lustredemo - simple code examples of liblustreapi functions
830 #include <stdio.h>
831 #include <fcntl.h>
832 #include <sys/stat.h>
833 #include <sys/types.h>
834 #include <dirent.h>
835 #include <errno.h>
836 #include <string.h>
837 #include <unistd.h>
838 #include <stdlib.h>
839 #include <lustre/liblustreapi.h>
840 #include <lustre/lustre_user.h>
841 #define MAX_OSTS 1024
842 #define LOV_EA_SIZE(lum, num) (sizeof(*lum) + num * sizeof(*lum->lmm_objects))
843 #define LOV_EA_MAX(lum) LOV_EA_SIZE(lum, MAX_OSTS)
850 This program provides crude examples of using the liblustre API functions
853 /* Change these definitions to suit */
858 #define TESTDIR "/tmp" /* Results directory */
859 #define TESTFILE "lustre_dummy" /* Name for the file we create/destroy */
860 #define FILESIZE 262144 /* Size of the file in words */
861 #define DUMWORD "DEADBEEF" /* Dummy word used to fill files */
862 #define MY_STRIPE_WIDTH 2 /* Set this to the number of OST required */
863 #define MY_LUSTRE_DIR "/mnt/lustre/ftest"
866 int close_file(int fd)
868 if (close(fd) < 0) {
869 fprintf(stderr, "File close failed: %d (%s)\n", errno, strerror(errno));
875 int write_file(int fd)
877 char *stng = DUMWORD;
880 for( cnt = 0; cnt < FILESIZE; cnt++) {
881 write(fd, stng, sizeof(stng));
885 /* Open a file, set a specific stripe count, size and starting OST
886 Adjust the parameters to suit */
888 int open_stripe_file()
890 char *tfile = TESTFILE;
891 int stripe_size = 65536; /* System default is 4M */
892 int stripe_offset = -1; /* Start at default */
893 int stripe_count = MY_STRIPE_WIDTH; /*Single stripe for this demo*/
894 int stripe_pattern = 0; /* only RAID 0 at this time */
898 rc = llapi_file_create(tfile,
899 stripe_size,stripe_offset,stripe_count,stripe_pattern);
900 /* result code is inverted, we may return -EINVAL or an ioctl error.
901 We borrow an error message from sanity.c
904 fprintf(stderr,"llapi_file_create failed: %d (%s) \n", rc, strerror(-rc));
907 /* llapi_file_create closes the file descriptor, we must re-open */
908 fd = open(tfile, O_CREAT | O_RDWR | O_LOV_DELAY_CREATE, 0644);
910 fprintf(stderr, "Can't open %s file: %d (%s)\n", tfile, errno, strerror(errno));
916 /* output a list of uuids for this file */
917 int get_my_uuids(int fd)
919 struct obd_uuid uuids[1024], *uuidp; /* Output var */
923 rc = llapi_lov_get_uuids(fd, uuids, &obdcount);
925 fprintf(stderr, "get uuids failed: %d (%s)\n",errno, strerror(errno));
927 printf("This file system has %d obds\n", obdcount);
928 for (i = 0, uuidp = uuids; i < obdcount; i++, uuidp++) {
929 printf("UUID %d is %s\n",i, uuidp->uuid);
934 /* Print out some LOV attributes. List our objects */
935 int get_file_info(char *path)
938 struct lov_user_md *lump;
942 lump = malloc(LOV_EA_MAX(lump));
947 rc = llapi_file_get_stripe(path, lump);
950 fprintf(stderr, "get_stripe failed: %d (%s)\n",errno, strerror(errno));
954 printf("Lov magic %u\n", lump->lmm_magic);
955 printf("Lov pattern %u\n", lump->lmm_pattern);
956 printf("Lov object id %llu\n", lump->lmm_object_id);
957 printf("Lov object group %llu\n", lump->lmm_object_gr);
958 printf("Lov stripe size %u\n", lump->lmm_stripe_size);
959 printf("Lov stripe count %hu\n", lump->lmm_stripe_count);
960 printf("Lov stripe offset %u\n", lump->lmm_stripe_offset);
961 for (i = 0; i < lump->lmm_stripe_count; i++) {
962 printf("Object index %d Objid %llu\n", lump->lmm_objects[i].l_ost_idx, lump->lmm_objects[i].l_object_id);
970 /* Ping all OSTs that belong to this filesysem */
979 sprintf(osc_dir, "/proc/fs/lustre/osc");
980 dir = opendir(osc_dir);
982 printf("Can't open dir\n");
985 while((d = readdir(dir)) != NULL) {
986 if ( d->d_type == DT_DIR ) {
987 if (! strncmp(d->d_name, "OSC", 3)) {
988 printf("Pinging OSC %s ", d->d_name);
989 rc = llapi_ping("osc", d->d_name);
991 printf(" bad\n");
993 printf(" good\n");
1009 sprintf(filename, "%s/%s",MY_LUSTRE_DIR, TESTFILE);
1011 printf("Open a file with striping\n");
1012 file = open_stripe_file();
1013 if ( file < 0 ) {
1014 printf("Exiting\n");
1021 printf("Getting uuid list\n");
1022 rc = get_my_uuids(file);
1023 rintf("Write to the file\n");
1024 rc = write_file(file);
1025 rc = close_file(file);
1026 printf("Listing LOV data\n");
1027 rc = get_file_info(filename);
1028 printf("Ping our OSTs\n");
1031 /* the results should match lfs getstripe */
1032 printf("Confirming our results with lfs getsrtipe\n");
1033 sprintf(sys_cmd, "/usr/bin/lfs getstripe %s/%s", MY_LUSTRE_DIR, TESTFILE);
1036 printf("All done\n");
1040 <para><emphasis role="bold">Makefile for sample application:</emphasis></para>
1042 gcc -g -O2 -Wall -o lustredemo libtest.c -llustreapi
1044 rm -f core lustredemo *.o
1047 rm -f /mnt/lustre/ftest/lustredemo
1048 rm -f /mnt/lustre/ftest/lustre_dummy
1049 cp lustredemo /mnt/lustre/ftest/
1051 <section remap="h5">
1052 <title>See Also</title>
1056 <xref linkend="dbdoclet.50438215_30970"/>
1061 <xref linkend="dbdoclet.50438215_50149"/>
1066 <xref linkend="dbdoclet.50438215_86607"/>
1071 <xref linkend="dbdoclet.50438215_12433"/>