Whamcloud - gitweb
Get an error from right dentry.
[fs/lustre-release.git] / lustre / mdt / mdt_xattr.c
index 83ecc74..47cce00 100644 (file)
@@ -1,32 +1,46 @@
 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
  * vim:expandtab:shiftwidth=8:tabstop=8:
  *
- *  linux/mdt/mdt_xattr.c
- *  Lustre Metadata Target (mdt) extended attributes management.
+ * GPL HEADER START
  *
- *  Copyright (C) 2002-2006 Cluster File Systems, Inc.
- *   Author: Peter Braam <braam@clusterfs.com>
- *   Author: Andreas Dilger <adilger@clusterfs.com>
- *   Author: Phil Schwan <phil@clusterfs.com>
- *   Author: Huang Hua <huanghua@clusterfs.com>
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
- *   This file is part of the Lustre file system, http://www.lustre.org
- *   Lustre is a trademark of Cluster File Systems, Inc.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 only,
+ * as published by the Free Software Foundation.
  *
- *   You may have signed or agreed to another license before downloading
- *   this software.  If so, you are bound by the terms and conditions
- *   of that agreement, and the following does not apply to you.  See the
- *   LICENSE file included with this distribution for more information.
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License version 2 for more details (a copy is included
+ * in the LICENSE file that accompanied this code).
  *
- *   If you did not agree to a different license, then this copy of Lustre
- *   is open source software; you can redistribute it and/or modify it
- *   under the terms of version 2 of the GNU General Public License as
- *   published by the Free Software Foundation.
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; If not, see
+ * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
  *
- *   In either case, Lustre is distributed in the hope that it will be
- *   useful, but WITHOUT ANY WARRANTY; without even the implied warranty
- *   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   license text for more details.
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ *
+ * GPL HEADER END
+ */
+/*
+ * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ * Use is subject to license terms.
+ */
+/*
+ * This file is part of Lustre, http://www.lustre.org/
+ * Lustre is a trademark of Sun Microsystems, Inc.
+ *
+ * lustre/mdt/mdt_xattr.c
+ *
+ * Lustre Metadata Target (mdt) extended attributes management.
+ *
+ * Author: Peter Braam <braam@clusterfs.com>
+ * Author: Andreas Dilger <adilger@clusterfs.com>
+ * Author: Phil Schwan <phil@clusterfs.com>
+ * Author: Huang Hua <huanghua@clusterfs.com>
  */
 
 #ifndef EXPORT_SYMTAB
@@ -59,7 +73,7 @@ static int mdt_getxattr_pack_reply(struct mdt_thread_info * info)
                 RETURN(-ENOMEM);
 
         /* Determine how many bytes we need */
-        if ((valid & OBD_MD_FLXATTR) == OBD_MD_FLXATTR) {
+        if (valid & OBD_MD_FLXATTR) {
                 xattr_name = req_capsule_client_get(pill, &RMF_NAME);
                 if (!xattr_name)
                         RETURN(-EFAULT);
@@ -71,7 +85,7 @@ static int mdt_getxattr_pack_reply(struct mdt_thread_info * info)
                 size = mo_xattr_get(info->mti_env,
                                     mdt_object_child(info->mti_object),
                                     &LU_BUF_NULL, xattr_name);
-        } else if ((valid & OBD_MD_FLXATTRLS) == OBD_MD_FLXATTRLS) {
+        } else if (valid & OBD_MD_FLXATTRLS) {
                 size = mo_xattr_list(info->mti_env,
                                      mdt_object_child(info->mti_object),
                                      &LU_BUF_NULL);
@@ -270,6 +284,7 @@ int mdt_reint_setxattr(struct mdt_thread_info *info,
         const struct lu_env     *env  = info->mti_env;
         struct lu_buf           *buf  = &info->mti_buf;
         struct mdt_reint_record *rr   = &info->mti_rr;
+        struct md_attr          *ma = &info->mti_attr;
         struct lu_attr          *attr = &info->mti_attr.ma_attr;
         struct mdt_object       *obj; 
         struct md_object        *child;
@@ -330,8 +345,15 @@ int mdt_reint_setxattr(struct mdt_thread_info *info,
         if (IS_ERR(obj))
                 GOTO(out, rc =  PTR_ERR(obj));
 
+        if (unlikely(!(valid & OBD_MD_FLCTIME))) {
+                CWARN("client miss to set OBD_MD_FLCTIME when "
+                      "setxattr: [object "DFID"] [valid %llu]\n",
+                      PFID(rr->rr_fid1), valid);
+                attr->la_ctime = cfs_time_current_sec();
+        }
+        attr->la_valid = LA_CTIME;
         child = mdt_object_child(obj);
-        if ((valid & OBD_MD_FLXATTR) == OBD_MD_FLXATTR) {
+        if (valid & OBD_MD_FLXATTR) {
                 char * xattr;
 
                 if (!req_capsule_field_present(pill, &RMF_EADATA, RCL_CLIENT)) {
@@ -369,9 +391,19 @@ int mdt_reint_setxattr(struct mdt_thread_info *info,
                         buf->lb_buf = xattr;
                         buf->lb_len = xattr_len;
                         rc = mo_xattr_set(env, child, buf, xattr_name, flags);
+                        /* update ctime after xattr changed */
+                        if (rc == 0) {
+                                ma->ma_attr_flags |= MDS_PERM_BYPASS;
+                                mo_attr_set(env, child, ma);
+                        }
                 }
-        } else if ((valid & OBD_MD_FLXATTRRM) == OBD_MD_FLXATTRRM) {
+        } else if (valid & OBD_MD_FLXATTRRM) {
                 rc = mo_xattr_del(env, child, xattr_name);
+                /* update ctime after xattr changed */
+                if (rc == 0) {
+                        ma->ma_attr_flags |= MDS_PERM_BYPASS;
+                        mo_attr_set(env, child, ma);
+                }
         } else {
                 CDEBUG(D_INFO, "valid bits: "LPX64"\n", valid);
                 rc = -EINVAL;