Whamcloud - gitweb
LU-12616 obclass: fix MDS start/stop race
[fs/lustre-release.git] / lustre / utils / liblustreapi_heat.c
1 /*
2  * LGPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * (C) Copyright (c) 2018, DataDirect Networks Inc, all rights reserved.
7  *
8  * All rights reserved. This program and the accompanying materials
9  * are made available under the terms of the GNU Lesser General Public License
10  * LGPL version 2.1 or (at your discretion) any later version.
11  * LGPL version 2.1 accompanies this distribution, and is available at
12  * http://www.gnu.org/licenses/lgpl-2.1.html
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * LGPL HEADER END
20  */
21 /*
22  * lustre/utils/liblustreapi_heat.c
23  *
24  * lustreapi library for heat
25  *
26  * Author: Li Xi <lixi@ddn.com>
27  */
28
29 #include <lustre/lustreapi.h>
30 #include <errno.h>
31 #include <sys/ioctl.h>
32
33 #include <libcfs/util/ioctl.h>
34 #include <lustre/lustreapi.h>
35 #include <linux/lustre/lustre_ioctl.h>
36 #include "lustreapi_internal.h"
37
38 /*
39  * Get heat of a file
40  *
41  * \param fd       File to get heat.
42  * \param heat     Buffer to save heat.
43  *
44  * \retval 0 on success.
45  * \retval -errno on failure.
46  */
47 int llapi_heat_get(int fd, struct lu_heat *heat)
48 {
49         int rc;
50
51         rc = ioctl(fd, LL_IOC_HEAT_GET, heat);
52         if (rc < 0) {
53                 llapi_error(LLAPI_MSG_ERROR, -errno, "cannot get heat");
54                 return -errno;
55         }
56         return 0;
57 }
58
59 /*
60  * Set heat of a file
61  *
62  * \param fd       File to get heat.
63  * \param heat     Buffer to save heat.
64  *
65  * \retval 0 on success.
66  * \retval -errno on failure.
67  */
68 int llapi_heat_set(int fd, __u64 flags)
69 {
70         int rc;
71
72         rc = ioctl(fd, LL_IOC_HEAT_SET, &flags);
73         if (rc < 0) {
74                 llapi_error(LLAPI_MSG_ERROR, -errno, "cannot set heat flags");
75                 return -errno;
76         }
77         return 0;
78 }