summaryrefslogtreecommitdiffstats
path: root/xlators/features/utime/src/utime-helpers.c
blob: c79e12badfa4982f747ae5c4ea228fdcea2fbf0c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
  Copyright (c) 2018 Red Hat, Inc. <http://www.redhat.com>
  This file is part of GlusterFS.

  This file is licensed to you under your choice of the GNU Lesser
  General Public License, version 3 or any later version (LGPLv3 or
  later), or the GNU General Public License, version 2 (GPLv2), in all
  cases as published by the Free Software Foundation.
*/

#include "utime-helpers.h"
#include "utime.h"

void
gl_timespec_get(struct timespec *ts)
{
#ifdef TIME_UTC
    timespec_get(ts, TIME_UTC);
#else
    timespec_now(ts);
#endif
}

void
utime_update_attribute_flags(call_frame_t *frame, xlator_t *this,
                             glusterfs_fop_t fop)
{
    utime_priv_t *utime_priv = NULL;

    if (!frame || !this) {
        goto out;
    }

    utime_priv = this->private;

    switch (fop) {
        case GF_FOP_SETXATTR:
        case GF_FOP_FSETXATTR:
            frame->root->flags |= MDATA_CTIME;
            break;

        case GF_FOP_FALLOCATE:
        case GF_FOP_ZEROFILL:
            frame->root->flags |= MDATA_MTIME;
            frame->root->flags |= MDATA_ATIME;
            break;

        case GF_FOP_OPENDIR:
        case GF_FOP_OPEN:
        case GF_FOP_READ:
            if (!utime_priv->noatime) {
                frame->root->flags |= MDATA_ATIME;
            }
            break;
        case GF_FOP_MKNOD:
        case GF_FOP_MKDIR:
        case GF_FOP_SYMLINK:
        case GF_FOP_CREATE:
            frame->root->flags |= MDATA_ATIME;
            frame->root->flags |= MDATA_CTIME;
            frame->root->flags |= MDATA_MTIME;
            frame->root->flags |= MDATA_PAR_CTIME;
            frame->root->flags |= MDATA_PAR_MTIME;
            break;

        case GF_FOP_UNLINK:
        case GF_FOP_RMDIR:
            frame->root->flags |= MDATA_CTIME;
            frame->root->flags |= MDATA_PAR_CTIME;
            frame->root->flags |= MDATA_PAR_MTIME;
            break;

        case GF_FOP_WRITE:
            frame->root->flags |= MDATA_MTIME;
            frame->root->flags |= MDATA_CTIME;
            break;

        case GF_FOP_LINK:
        case GF_FOP_RENAME:
            frame->root->flags |= MDATA_CTIME;
            frame->root->flags |= MDATA_PAR_CTIME;
            frame->root->flags |= MDATA_PAR_MTIME;
            break;

        case GF_FOP_TRUNCATE:
        case GF_FOP_FTRUNCATE:
            frame->root->flags |= MDATA_CTIME;
            frame->root->flags |= MDATA_MTIME;
            break;

        case GF_FOP_REMOVEXATTR:
        case GF_FOP_FREMOVEXATTR:
            frame->root->flags |= MDATA_CTIME;
            break;

        default:
            frame->root->flags = 0;
    }
out:
    return;
}