@@ -319,8 +319,7 @@ static struct ceph_vxattr *ceph_match_vxattr(struct inode *inode,
319319static int __set_xattr (struct ceph_inode_info * ci ,
320320 const char * name , int name_len ,
321321 const char * val , int val_len ,
322- int dirty ,
323- int should_free_name , int should_free_val ,
322+ int flags , int update_xattr ,
324323 struct ceph_inode_xattr * * newxattr )
325324{
326325 struct rb_node * * p ;
@@ -349,12 +348,25 @@ static int __set_xattr(struct ceph_inode_info *ci,
349348 xattr = NULL ;
350349 }
351350
351+ if (update_xattr ) {
352+ int err = 0 ;
353+ if (xattr && (flags & XATTR_CREATE ))
354+ err = - EEXIST ;
355+ else if (!xattr && (flags & XATTR_REPLACE ))
356+ err = - ENODATA ;
357+ if (err ) {
358+ kfree (name );
359+ kfree (val );
360+ return err ;
361+ }
362+ }
363+
352364 if (!xattr ) {
353365 new = 1 ;
354366 xattr = * newxattr ;
355367 xattr -> name = name ;
356368 xattr -> name_len = name_len ;
357- xattr -> should_free_name = should_free_name ;
369+ xattr -> should_free_name = update_xattr ;
358370
359371 ci -> i_xattrs .count ++ ;
360372 dout ("__set_xattr count=%d\n" , ci -> i_xattrs .count );
@@ -364,7 +376,7 @@ static int __set_xattr(struct ceph_inode_info *ci,
364376 if (xattr -> should_free_val )
365377 kfree ((void * )xattr -> val );
366378
367- if (should_free_name ) {
379+ if (update_xattr ) {
368380 kfree ((void * )name );
369381 name = xattr -> name ;
370382 }
@@ -379,8 +391,8 @@ static int __set_xattr(struct ceph_inode_info *ci,
379391 xattr -> val = "" ;
380392
381393 xattr -> val_len = val_len ;
382- xattr -> dirty = dirty ;
383- xattr -> should_free_val = (val && should_free_val );
394+ xattr -> dirty = update_xattr ;
395+ xattr -> should_free_val = (val && update_xattr );
384396
385397 if (new ) {
386398 rb_link_node (& xattr -> node , parent , p );
@@ -588,7 +600,7 @@ static int __build_xattrs(struct inode *inode)
588600 p += len ;
589601
590602 err = __set_xattr (ci , name , namelen , val , len ,
591- 0 , 0 , 0 , & xattrs [numattr ]);
603+ 0 , 0 , & xattrs [numattr ]);
592604
593605 if (err < 0 )
594606 goto bad ;
@@ -892,7 +904,7 @@ int __ceph_setxattr(struct dentry *dentry, const char *name,
892904 struct ceph_inode_info * ci = ceph_inode (inode );
893905 int issued ;
894906 int err ;
895- int dirty ;
907+ int dirty = 0 ;
896908 int name_len = strlen (name );
897909 int val_len = size ;
898910 char * newname = NULL ;
@@ -954,11 +966,13 @@ int __ceph_setxattr(struct dentry *dentry, const char *name,
954966 }
955967
956968 err = __set_xattr (ci , newname , name_len , newval ,
957- val_len , 1 , 1 , 1 , & xattr );
969+ val_len , flags , 1 , & xattr );
958970
959- dirty = __ceph_mark_dirty_caps (ci , CEPH_CAP_XATTR_EXCL );
960- ci -> i_xattrs .dirty = true;
961- inode -> i_ctime = CURRENT_TIME ;
971+ if (!err ) {
972+ dirty = __ceph_mark_dirty_caps (ci , CEPH_CAP_XATTR_EXCL );
973+ ci -> i_xattrs .dirty = true;
974+ inode -> i_ctime = CURRENT_TIME ;
975+ }
962976
963977 spin_unlock (& ci -> i_ceph_lock );
964978 if (dirty )
0 commit comments